[Solved] Why IF condition is not fulfilled on android [duplicate]


It shouldn’t continue, it should throw a NullPointerException that you may intercept in the catch block.

When you try

if (!spnOptionSelectedTypes.equals(null))

it should throw this exception because spnOptionSelectedTypes is null so it is not a String and does not have any equals() method.

Edit:

It allows the first if to pass because it has 2 tests

if (A OR B) {

If A is true, the B condition is not tested because only one is required to continue, because of the OR operator.

Edit 2:

With:

if (A AND B) {

If A is true, B will also be tested and throw a NullPointerException if spnOptionSelectedCities is null.

Definitive answer:

Null tests in Java

if (x != null && y != null) {
    x.doSomething();
    y.doSomethingElse();
}

4

solved Why IF condition is not fulfilled on android [duplicate]