mercredi 28 octobre 2015

If condition broken: get into when condition is false and skip lines

Programming with java on android, I'm facing a very weird problem those days.

This is basically my condition:

ContentValues values = null;
boolean condition=((!(name.equals(stateString))) && (!(stateString.equals(""))));

     if(condition)
     {
                   // UPDATE STATE NAME INTO DB
                  values = new ContentValues();
                  values.put("state_name", countryString);
                  sql.update("STATE", values, "_id=" + state, null);
     }

The problem is, when condition is false, the IDE is going into the condition anyway, and it skips the two first lines.

Basically, instead of skipping the statement, it directly goes to :

sql.update("STATE", values, "_id=" + state, null);

even if condition is false...

I have no idea of why this is happening. I try to make the condition simpler, but the problem remains. I also checked for a possible ; I could have forget after a condition, but everything seems to be good.

I have to add that this is happening in an AsyncTask during the doInBackground process. I'm using android-studio.

Any help would be appreciated!

Aucun commentaire:

Enregistrer un commentaire