0

I using a web services to get the value, make the long story short. I can get the value from webservices, for this case, the value for strVersion is 1(the for loop only return 1 record since there is only 1 record).

Now here is the problem, the result always return "Wrong: 1" instead of "OK: 1", come someone please tell me why? the datatype in MYSQL for this field is Varchar.

    AndroidHttpTransport aht = new AndroidHttpTransport(URL);
    aht.call(SOAP_ACTION, soapEnvelope);
    SoapObject resultString = (SoapObject) soapEnvelope.getResponse();

    final String[] strVersion = new String[resultString.getPropertyCount()];

    for(int i =0; i<resultString.getPropertyCount(); i++)
    {
        SoapObject array = (SoapObject) resultString .getProperty(i);
        strVersion[i] = array.getProperty(0).toString();                    
        if(strVersion[i] == "1")
        {
        Toast.makeText(getApplicationContext(), "OK: " + strVersion[i], Toast.LENGTH_SHORT).show();
        }
        else
        {
             Toast.makeText(getApplicationContext(), "Wrong: " + strVersion[i], Toast.LENGTH_SHORT).show();
        }
    }
melvintcs
  • 551
  • 3
  • 13
  • 34

1 Answers1

4

Do String comparison using equals().

Change this:

if(strVersion[i] == "1")

to

if(strVersion[i].equals("1"))

Read this for more information.

== compares references,not the values. In your case, you want to check for the value equality, not the reference equality.

Community
  • 1
  • 1
Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108