0

i have a registration function that registers a user in my app. If registration is successfull, my webapi will return "success" otherwise "error".

this part will ALWAYS be "else" even if my status variable is "success":

if(register_response=="success") {

http://pastie.org/private/jizl7udishhbdgvf5qlb9q

How can that be? i cannot see the error :|

user207421
  • 305,947
  • 44
  • 307
  • 483
pila
  • 928
  • 3
  • 11
  • 28

1 Answers1

3

This is java related.

When comparing String you should use equals()

Community
  • 1
  • 1
florianmski
  • 5,603
  • 1
  • 17
  • 14
  • 2
    This may be a language thing, and I might be accused of being pedantic, but it's not "a Java issue". It makes complete sense. String is an object. The equality operator, when applied to two objects, tests whether the two objects (either side of the operator) are the same object. If you compare an existing String object with a constant string, they cannot be the same since they are two different objects. The "equals()" method is provided to test for equality of values. – Simon Sep 09 '12 at 21:25
  • @Simon You're right, I meant "java related". Thanks for the clarification! – florianmski Sep 09 '12 at 21:26