Why doesn't this if statement work? - java

I'm trying to create an if statement, for example if the user doesn't type anything into the the two edit text's, then it displays a toast and resets everything. But for some reason, my code completely ignores this and just goes to the else statement instead.
Can anyone help?
My Code:
package com.gta5news.bananaphone;
import java.io.File;
import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class LogIn extends Activity implements OnClickListener {
Button send;
EditText user;
EditText pass;
CheckBox staySignedIn;
SharedPreferences shareduser;
SharedPreferences sharedpass;
public static String settings = "MySharerdUser";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
send = (Button) findViewById(R.id.bLogIn);
user = (EditText) findViewById(R.id.eTuser);
pass = (EditText) findViewById(R.id.eTpassword);
staySignedIn = (CheckBox) findViewById(R.id.Cbstay);
send.setOnClickListener(this);
SharedPreferences settings = getPreferences(MODE_PRIVATE);
String name = settings.getString("name", "");
String password = settings.getString("pwd", "");
user.setText(name);
pass.setText(password);
if (staySignedIn.isChecked()) {
SharedPreferences MySharedUser = getPreferences(MODE_PRIVATE);
settings.edit().putString("name", user.getText().toString())
.putString("pwd", pass.getText().toString()).commit();
}
if (user.length() > 0)
;
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bLogIn:
if (user.length() < 0)
Toast.makeText(this,
"Try to type in your username and password again!",
Toast.LENGTH_LONG).show();
else {
String u = user.getText().toString();
String p = pass.getText().toString();
Bundle send = new Bundle();
send.putString("key", u);
send.putString("key", p);
Intent a = new Intent(LogIn.this, FTPClient.class);
startActivity(a);
Toast.makeText(this, "Yay, you signed in!", Toast.LENGTH_LONG)
.show();
break;
}
}
}
}

if (user.length() == 0)
try it because user.length() is never come in Less Than Zero

You have to use
user.getText().toString().length()

Do you need an onClickListener for you checkbox???
checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks, depending on whether it's now checked
if (((CheckBox) v).isChecked()) {
Toast.makeText(HelloFormStuff.this, "Selected", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(HelloFormStuff.this, "Not selected", Toast.LENGTH_SHORT).show();
}
}
});

Related

2 Edit text get currency format(###,###,###) and mines but (crash when clicked on btn mines)

here is the java code :
package com.aliabbasi.mytamrin;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.text.DecimalFormat;
public class full extends AppCompatActivity {
EditText full_payment, cash_payment,remain_payment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full);
Toast.makeText(this, "مقادیر را با دقت وارد کنید", Toast.LENGTH_LONG).show();
Button btn_cancel = findViewById(R.id.btn_cancel);
btn_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent btn_cancel = new Intent(full.this, MainActivity.class);
startActivities(new Intent[]{btn_cancel});
}
});
try {
Button remain_check = findViewById(R.id.remain_btn);
remain_check.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
full_payment = findViewById(R.id.edt_full_payment);
cash_payment = findViewById(R.id.edt_cash_payment);
remain_payment = (EditText) findViewById(R.id.edt_remain);
Float a = Float.parseFloat(full_payment.getText().toString());
Float b = Float.parseFloat(cash_payment.getText().toString());
Float s = a - b;
String r = Double.toString(s);
remain_payment.setText(r);
}
});
} catch (Exception e) {
Toast.makeText(this, "خطایی رح داده" + e, Toast.LENGTH_LONG).show();
}
try {
EditText editText= (EditText) findViewById(R.id.edt_full_payment);
editText.addTextChangedListener(new MyNumberWatcher(editText));
}
catch (Exception e){
Toast.makeText(this, "ERR"+e, Toast.LENGTH_LONG).show();
}
try {
EditText editText= (EditText) findViewById(R.id.edt_cash_payment);
editText.addTextChangedListener(new MyNumberWatcher(editText));
}
catch (Exception e){
Toast.makeText(this, "ERR"+e, Toast.LENGTH_LONG).show();
}
/*try {
EditText editText= (EditText) findViewById(R.id.edt_remain);
editText.addTextChangedListener(new MyNumberWatcher(editText));
}
catch (Exception e){
Toast.makeText(this, "ERR"+e, Toast.LENGTH_LONG).show();
}*/
}
}
i try the double variable
there is no Error but program crashed when i press the remain_btn.
i check the Debug and find out there is a problem with this:
at com.aliabbasi.mytamrin.full$2.onClick(full.java:45).
andNumberFormatException** but IDK how to solve it.**
and i really like to know how fix this becase i stuck in this about 2 days...
thanks for reading ...
wish the best
code imag
You can do something like this. Remove that comma.
Float a = Float.parseFloat(full_payment.getText().toString().replace(",", ""));

Didn't Understand which data type is name.gettext().tostring()

I am building an app that toastes Welcome when only specific email and password is inputted. Otherwise it says Incorrect Email/password. But I don't understand what the problem with my code is. I think the problem is within string.gettext().toString(). I do not know how to use it in the if-else-loop...
package com.example.project2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class Project2 extends AppCompatActivity {
public void login(View view) {
EditText email = (EditText) findViewById(R.id.emailEditText);
EditText password = (EditText) findViewById(R.id.passwordEditText);
Log.i("info","Button pressed!");
String Email = email.getText().toString();
String Password = password.getText().toString();
boolean email1 = Email.contains("example876#gmail.com");
boolean password1 = Password.contains("asad123");
if (email1){
Toast.makeText(this, "Welcome", Toast.LENGTH_LONG).show();
} else if (password1) {
Toast.makeText(this, "The method worked", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Incorrect Username/Password", Toast.LENGTH_LONG).show();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_project2);
}
}
Somebody plz help!!
THanks in advance...

Session Manager using Shared Pref

I'm using shared preference to store user data, and in my start screen, I want to check whether username has already logged in or not, when user is still not logged out yet it will redirect to UserView.java when the application starts, otherwise it will go to LoginActivity.java
I've used these tutorial as my references :
Android Hive Tutorial Shared Pref, and
Android example tutorial Shared Pref..
but when I exit my activity without logging out, next time I open my application it's status is logged out (its like the session has ended although I have not logged out yet from my application),,
What should I do to fix this thing, so whenever I exit my application (without logging out) my data is still there in shared pref and will be redirected to UserView.java, Am i making any mistakes with my codes?
These are my code:
userSessionManager.java
package com.thesis.teamizer;
import java.util.HashMap;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
public class userSessionManager {
// Shared Preferences Reference
SharedPreferences CurrentSession;
// Editor Reference for Editing Shared Preferences
Editor editor;
// Context Reference
Context _context;
// Shared pref mode
int PRIVATE_MODE = 0;
// Sharef Preferences Name
public static String PrefName = "MyUsername";
// All Shared Preferences Keys
private static final String IS_USER_LOGIN = "IsUserLoggedIn";
// User name (make variable public to access from outside)
public static final String KEY_USERNAME = "username";
// Constructor
public userSessionManager(Context context) {
this._context = context;
CurrentSession = _context.getSharedPreferences(PrefName, PRIVATE_MODE);
editor = CurrentSession.edit();
}
public void createUserLogin(String username) {
// User has already login
editor.putBoolean(IS_USER_LOGIN, true);
// Storing username in pref
editor.putString(KEY_USERNAME, username);
// Editor ready to execute the previous codes
editor.commit();
}
public boolean checkLogin() {
// Check login status. If the user is not logged in
if (!this.isUserLoggedIn()) {
return true;
}
return false;
}
// Read session using hashmap
public HashMap<String, String> getUserDetails() {
// Use hashmap to store user credentials
HashMap<String, String> user = new HashMap<String, String>();
// user name
user.put(KEY_USERNAME, CurrentSession.getString(KEY_USERNAME, null));
// return user
return user;
}
public void logOut() {
// clearing all data from Shared pref
editor.remove(KEY_USERNAME);
editor.clear();
editor.commit();
}
// Will check if the user is Login or not by getting the boolean of
// IS_USER_LOGIN from CurrentSession(pref)
private boolean isUserLoggedIn() {
// TODO Auto-generated method stub
return CurrentSession.getBoolean(IS_USER_LOGIN, false);
}
}
LoginActivity.java
package com.thesis.teamizer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends Activity implements View.OnClickListener {
private EditText etUsername;
private EditText etPassword;
private Button bLogin, bRegis, bAdmin;
userSessionManager session;
String loginUrl;
JSONParser jsonParser = new JSONParser();
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
private ProgressDialog pDialog;
String Username;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login_screen);
Declaration();
bLogin.setOnClickListener(this);
bRegis.setOnClickListener(this);
bAdmin.setOnClickListener(this);
if (session.checkLogin()) {
Intent intent = new Intent("com.thesis.teamizer.USERVIEW");
finish();
startActivity(intent);
}
}
private void Declaration() {
// TODO Auto-generated method stub
etUsername = (EditText) findViewById(R.id.etLoginUsername);
etPassword = (EditText) findViewById(R.id.etLoginPassword);
bLogin = (Button) findViewById(R.id.bLogin);
bRegis = (Button) findViewById(R.id.bRegister);
bAdmin = (Button) findViewById(R.id.bAdminadmin);
session = new userSessionManager(getApplicationContext());
HashMap<String, String> user = session.getUserDetails();
Username = user.get(userSessionManager.KEY_USERNAME);
myIP ip = new myIP();
String myIp = ip.getIp();
String thisPhp = "doLogin.php";
loginUrl = myIp + thisPhp;
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bLogin:
new AttemptLogin().execute();
break;
case R.id.bRegister:
Intent i = new Intent("com.thesis.teamizer.REGISTRATIONACTIVITY");
startActivity(i);
break;
}
class AttemptLogin extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
boolean failure = false;
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
#Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
// Check for success tag
int success;
String username = etUsername.getText().toString();
String password = etPassword.getText().toString();
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(loginUrl, "POST",
params);
// check your log for json response
Log.d("Login attempt", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Login Successful!", json.toString());
String currentLoginUsername = username;
session.createUserLogin(currentLoginUsername);
Intent intent = new Intent("com.thesis.teamizer.USERVIEW");
finish();
startActivity(intent);
String sukses = "Sukses login";
return sukses;
} else if (success == 0) {
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();
Toast.makeText(getApplicationContext(), file_url,
Toast.LENGTH_SHORT).show();
}
}
}
UserView.java
package com.thesis.teamizer;
import java.util.HashMap;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class UserView extends Activity implements View.OnClickListener {
public Button createGr, viewGr, createAn, viewAn, notification, logout,
calendar, createEvent, myEvent, createTask, myTask;
public String Username;
userSessionManager session;
Intent i;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.user_view);
sessionAndDeclaration();
createGr.setOnClickListener(this);
viewGr.setOnClickListener(this);
createAn.setOnClickListener(this);
viewAn.setOnClickListener(this);
notification.setOnClickListener(this);
logout.setOnClickListener(this);
createEvent.setOnClickListener(this);
calendar.setOnClickListener(this);
myEvent.setOnClickListener(this);
createTask.setOnClickListener(this);
myTask.setOnClickListener(this);
}
private void sessionAndDeclaration() {
// TODO Auto-generated method stub
session = new userSessionManager(getApplicationContext());
HashMap<String, String> user = session.getUserDetails();
// get name
Username = user.get(userSessionManager.KEY_USERNAME);
TextView a = (TextView) findViewById(R.id.tvUserVUsername);
a.setText(Username);
createGr = (Button) findViewById(R.id.bCreateGroup);
viewGr = (Button) findViewById(R.id.bViewMyGroup);
createAn = (Button) findViewById(R.id.bCreateAnnouncement);
viewAn = (Button) findViewById(R.id.bViewMyAnnouncement);
notification = (Button) findViewById(R.id.bNotification);
logout = (Button) findViewById(R.id.bDoLogout);
calendar = (Button) findViewById(R.id.bGoToMyCalendar);
createEvent = (Button) findViewById(R.id.bCreateEvent);
myEvent = (Button) findViewById(R.id.bGoToMyEvent);
createTask = (Button) findViewById(R.id.bGoToCreateTask);
myTask = (Button) findViewById(R.id.bGoToMyTask);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bCreateGroup:
i = new Intent("com.thesis.teamizer.CREATEGROUPACTIVITY");
startActivity(i);
break;
case R.id.bViewMyGroup:
i = new Intent("com.thesis.teamizer.MYGROUPACTIVITY");
startActivity(i);
break;
case R.id.bCreateAnnouncement:
i = new Intent("com.thesis.teamizer.CREATEANNOUNCEMENTACTIVITY");
startActivity(i);
break;
case R.id.bViewMyAnnouncement:
i = new Intent("com.thesis.teamizer.VIEWALLANNOUNCEMENT");
startActivity(i);
break;
case R.id.bNotification:
i = new Intent("com.thesis.teamizer.NOTIFICATION");
startActivity(i);
break;
case R.id.bDoLogout:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to Logout?")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
finish();
session.logOut();
Intent i = new Intent(
"com.thesis.teamizer.LOGINACTIVITY");
// Closing all the Activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// Add new Flag to start new Activity
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Staring Login Activity
startActivity(i);
finish();
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
break;
case R.id.bGoToMyCalendar:
i = new Intent("com.thesis.teamizer.VIEWCALENDAR");
startActivity(i);
break;
case R.id.bCreateEvent:
i = new Intent("com.thesis.teamizer.CREATEEVENT");
startActivity(i);
break;
case R.id.bGoToMyEvent:
i = new Intent("com.thesis.teamizer.MYEVENT");
startActivity(i);
break;
case R.id.bGoToCreateTask:
i= new Intent("com.thesis.teamizer.CREATETASK");
startActivity(i);
break;
case R.id.bGoToMyTask:
i = new Intent("com.thesis.teamizer.MYTASK");
startActivity(i);
break;
}
}
}

Cannot Export sharedpreferences to CSV Android

Okay So this is an activity class where I am trying to export my sharedPreferences that are saved to a CSV file. This does not work. What am I doing wrong? How do I correctly write the sharedPreferences items to a CSV file?
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class Admin extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin);
Button btViewContacts = (Button)findViewById(R.id.btnViewContacts);
Button btDeleteContacts = (Button)findViewById(R.id.btnDeleteContacts);
Button btExportCSV = (Button)findViewById(R.id.btnExportCSV);
final Context context = this;
final SharedPreferences sharedPref = PreferenceManager
.getDefaultSharedPreferences(this);
btViewContacts.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(Admin.this, Contacts.class));
}
});
btDeleteContacts.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//DISPLAY ALERT DIALOG
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); //show an alertDialog when user selects delete radio button and clicks process, prompt to confirm
//set title
alertDialogBuilder.setTitle("DELETE ALL CONTACTS?");
//set dialog message
alertDialogBuilder
.setMessage("Are you sure you want to delete ALL acquired contact info?")
.setCancelable(true)
//no button
.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) { //if user selects no, close dialog
// TODO Auto-generated method stub
//if clicked this will close the dialog and do nothing.
dialog.cancel();
}
})
//yes button
.setPositiveButton("Yes", new DialogInterface.OnClickListener() { //if user selects yes, clear the shared preferences and display confirmation message when deleted.
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
//if this button is clicked it will erase the values in memory
SharedPreferences.Editor editor = sharedPref.edit();
editor.clear();
editor.commit();
//displays toast message confirming deletion of race info
Toast.makeText(Admin.this, "Contact Info Deleted.", Toast.LENGTH_SHORT).show();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
Map<String, ?> allEntries = sharedPref.getAll();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
Log.d("TAG", entry.getKey() + ": " + entry.getValue().toString());
}
btExportCSV.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
generateCsvFile(Environment.getExternalStorageDirectory().getPath());
}
});
}
private void generateCsvFile(String sFileName)
{
final SharedPreferences sharedPref = PreferenceManager
.getDefaultSharedPreferences(this);
String delimiter = ",";
try
{
FileWriter writer = new FileWriter(sFileName);
writer.append("First Name");
writer.append(',');
writer.append("Last Name");
writer.append(',');
writer.append("Email");
writer.append(',');
writer.append("Phone");
writer.append(',');
writer.append("Address");
writer.append(',');
writer.append("City");
writer.append(',');
writer.append("State");
writer.append(',');
writer.append("Zip");
writer.append('\n');
Map<String, ?> allEntries = sharedPref.getAll();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
Map<String,?> all = sharedPref.getAll();
Iterator it = all.entrySet().iterator();
Map.Entry pairs = (Map.Entry)it.next();
if (pairs.getKey().toString().startsWith("contactid_")) {
String strContact = sharedPref.getString((String)pairs.getKey(), "");
String[] data = TextUtils.split(strContact, delimiter);
writer.write(strContact);
writer.append('\n');
}
Toast.makeText(Admin.this, "ContAcq's Exported to .CSV.", Toast.LENGTH_SHORT).show();
//generate whatever data you want
writer.flush();
writer.close();
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}

EditText gives NullPointerException on getText

I'm kinda new and any help would be appreciated
Currently either it's filled it in or I'm getting a toast saying there is a nullpointer.
In the if else statement it will always jump to the else part. So the if doesn't seem to tihnk it's empty while that is what I'm getting in the toast(Created in the catch)
package com.example.domoticaapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class CreateProfile extends Activity implements OnClickListener
{
//Declare Variables
DBAdapter myDb;
EditText ipInput, nameInput;
Button save;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.create_profile);
ipInput = (EditText) findViewById(R.id.ipInput);
nameInput = (EditText) findViewById(R.id.nameInput);
save = (Button) findViewById(R.id.save);
save.setOnClickListener(this);
}
private void saveProfile()
{
String IP = ipInput.getText().toString();
String name = nameInput.getText().toString();
if(IP == null || name == null || IP == "" || name == "")
{
Toast.makeText(this, "Name and IP can't be empty!", Toast.LENGTH_SHORT).show();
}
else
{
try
{
myDb.insertRow(name, IP);
//Intent i = new Intent("com.example.domoticaapp.SQLView");
//startActivity(i);
}
catch(Exception e)
{
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
}
}
}
#Override
public void onClick(View v)
{
switch(v.getId())
{
case R.id.save:
saveProfile();
break;
}
}
}
Try this.
if(!IP.equals("") && !name.equals(""))
{
/** Your Code **/
}
else
{
Toast.makeText(this, "Name and IP can't be empty!", Toast.LENGTH_SHORT).show();
}
try this
if(TextUtils.isEmpty(name ) &&TextUtils.isEmpty(IP)){
Toast....
}else{
...
}
DBAdapter myDb;
myDb has not been intialised. You just declared it

Categories