dimanche 22 novembre 2015

String Comparison error in a android code [duplicate]

This question already has an answer here:

I am using the simple code for Sqlite database saving and retrieval. My problem is my code takes always the else part even the strings are same. Toast.makeText(getApplicationContext(), "No UName: "+utext+","+str+"; Pswd: "+ptext+","+str1, Toast.LENGTH_LONG).show();

instead of, Toast.makeText(getApplicationContext(), "Yes UName: "+utext+","+str+"; Pswd: "+ptext+","+str1, Toast.LENGTH_LONG).show();

I checked the output with toast and with debug mode. The value of utext is equal to str and the value of ptext is equal to str1. Is anything I made mistake here? I don't find anything.

http://ift.tt/1I4KtYQ

public void onClick(View v) {
            utext=t1.getText().toString();
            ptext=t2.getText().toString();

            Cursor c = db.rawQuery("SELECT * FROM " + tbl_name+" WHERE USERNAME= '"+utext+"' AND PASSWORD= '"+ptext+"'", null);
              if(c.moveToLast() ) {
                      str=c.getString(c.getColumnIndex("USERNAME"));
                      str1=c.getString(c.getColumnIndex("PASSWORD"));
                      Toast.makeText(getApplicationContext(), "True : "+str+", "+str1, Toast.LENGTH_LONG).show();
              }
              else
                  Toast.makeText(getApplicationContext(), "FALSE", Toast.LENGTH_LONG).show();
              if(str==utext || str1==ptext)
                  Toast.makeText(getApplicationContext(), "Yes UName: "+utext+","+str+"; Pswd: "+ptext+","+str1, Toast.LENGTH_LONG).show();
              else
                  Toast.makeText(getApplicationContext(), "No UName: "+utext+","+str+"; Pswd: "+ptext+","+str1, Toast.LENGTH_LONG).show();

        }

Aucun commentaire:

Enregistrer un commentaire