1

My problem is that this won't work:

if (result.equals("success")) { Toast.makeText(MainActivity.myContext, "Hausaufgabe eingetragen!", Toast.LENGTH_LONG).show(); startSync(lv); } else if (result.equals("already exists")) { Toast.makeText(MainActivity.myContext, "Hausaufgabe wurde bereits eingetragen!", Toast.LENGTH_LONG).show(); } else if (result.equals("user not exists")){ Toast.makeText(MainActivity.myContext, "Das eingespeicherte Benutzerkonto ist ungültig oder gelöscht worden!", Toast.LENGTH_LONG).show(); } else if (result.equals("server problem")){ Toast.makeText(MainActivity.myContext, "Ein Server Problem ist aufgetreten!\n" + "Bitte melden!", Toast.LENGTH_LONG).show(); } else { Toast.makeText(MainActivity.myContext, "Unbekannte Rückmeldung des Servers:\n" + result, Toast.LENGTH_LONG).show(); } Log.d("API",result); 

LogCat says API:success, but feedback in the app is "Unbekannte Rückmeldung des Servers: success"

2
  • 10
    Did you make sure the value is trimmed? In other words, no whitespace around the string? Commented Nov 5, 2014 at 19:05
  • 2
    also equals is case sensitive Commented Nov 5, 2014 at 19:15

1 Answer 1

2

Use the trim() method, because your variable result probably contains an space, like " success":

if (result.trim().equals("success")) { ... ... 

you could complement with toLowerCase() method, to prevent the handle of capitalized letters like " Success":

 if (result.trim().toLowerCase().equals("success")) { ... ... 

or try using indexOf() method

for example:

if (result.indexOf("success") > 0) { ... ... 
Sign up to request clarification or add additional context in comments.

3 Comments

index of worked for me! Thank you! But i have a question: why doesn't it work with equals or trim, my browsers show the api correctly?
Mr Androider if your variable "result" has de value of "success", using equals must be enough; if your variable "result" has de value of " success ", "success " or " success " .trim().equals() will do the job; check if the variable "result" really has the value of "success", probably has for example "is´t a success", the trim().equals() doesn´t work here.
My browsers told me "succcess", Logcat told me "success", Toast told me " success"?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.