android - String.equals() always returns false? -
i trying make sign in page android app. team leader has decided make webservice.
whenever uses logs in, request sent, 3 possible responses:
0: wrong password 20: wrong username otherwise: uuid
i trying validate results given webservice this:
string resultstring = result.tostring(); if (resultstring.equals("20")) { toast.maketext(getbasecontext(), "het ingevulde emailadres klopt niet!", toast.length_long).show(); return; } else if (resultstring.equals("0")) { toast.maketext(getbasecontext(), "het ingevulde wachtwoord klopt niet!", toast.length_long).show(); return; } else { toast.maketext(getbasecontext(), "debug, klopt", toast.length_long).show(); return; }
seems basic code me. however, code shows bottom statement, lets first 2 pass false.
for debugging purposes, returning resultstring
console. (removed line in sample). there can see result given in fact 20
.
how can such simple code not want do?
thanks.
response not string comparing "0" , "20". response
0: wrong password 20: wrong username otherwise: uuid
if want compare string should
options : 1
string resultstring = result.tostring(); if (resultstring.equals("20: wrong username")) { // code } else if (resultstring.equals("0: wrong password")) { // code } else { // code }
option : 2
instead of eqauls
should use contains
string resultstring = result.tostring(); if (resultstring.contains("20")) { // code } else if (resultstring.contains("0")) { // code } else { // code }
Comments
Post a Comment