0

I need to create a login password for a user in my android app. The first part compares the setPass and the confirmation pass then saves it in the db. My problem is that else is never run Here is my code below...

 savePass.setOnClickListener(new OnClickListener() { public void onClick(View v) { if(setPass.getText().toString() !=conPass.getText().toString()){ Log.d("login", "Checking whether passwords created ok"); Log.d("login", "setPass: " + setPass.getText().toString()); Log.d("login", "conPass: " + conPass.getText().toString()); error.setText("Passwords do not match!"); }else{ Log.d("login", "showing dialog 0 "); showDialog(0); Log.d("login", "Instantiating loginNew"); Login login = new Login(); login.setPassword(setPass.toString()); Log.d("login", "Adding to db"); db.addPassword(login); Log.d("login", "opening main login form"); Intent intent = new Intent("com.philsoft.budget.activity_main"); startActivity(intent); } } }); 
1
  • Really, is this how you debug ? Log between each every statement ? Havn't you heard of something called the Debugger ? Commented Jan 31, 2013 at 8:15

2 Answers 2

2

Do not compare the two string with == operator. Use String.equals() instead.

if(setPass.getText().toString().equals(conPass.getText().toString())){ // your necessary codes } else { } 

You have to remember, == compares the object references, not the content.

Sign up to request clarification or add additional context in comments.

Comments

0

Try with this:

if(!setPass.getText().toString().equals( conPass.getText().toString()) ){ 

When use the == or != with objects compares the memory reference, not the actual value. To compare the value should use the equals().

Hope it helps.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.