mardi 24 février 2015

Why IF condition is not fulfilled on android

I just want to know why the compiler allow to continue the program normally in this condition:



public void ButtonOnClickDirectoryList(View v){
try {
if (!spnOptionSelectedDepartment.equals(null) || !spnOptionSelectedCities.equals(null)) {
if (!spnOptionSelectedTypes.equals(null)) { //code....}


the spnOptionSelectedDepartment and spnOptionSelectedTypes are Strings and are defined at the begining of the class like this:



private String spnOptionSelectedDepartment = null;
private String spnOptionSelectedCities = null;


so when I press the button, it call this method and this are the values that I have in the moment:



spnOptionSelectedDepartment = "9999"
spnOptionSelectedCities = null
spnOptionSelectedTypes = null


so when I put a break point on this condition it just continue validating the rest of the code inside that if... Could anybody explain me why this behavior?


Let me edit the question, Yes it throws nullpointer exception on the second if...



if (!spnOptionSelectedTypes.equals(null)) {


but why it allows the first IF when spnOptionSelectedCities = null...?


Aucun commentaire:

Enregistrer un commentaire