forum

Home / DeveloperSection / Forums / !array[0].isEmpty() returning NullPointer?

!array[0].isEmpty() returning NullPointer?

Anonymous User 1856 18-Nov-2014

Here's my code:

if (!quizDescs[0].isEmpty()) {
    mDescText.setText(quizDescs[0]);
} else {
    mDescText.setVisibility(View.INVISIBLE);
}

So, when this code runs, and the if condition returns true, everything is fine and dandy, however, if it returns false, it says there's a NullPointerException, and points me to the line of code containing the if statement.

Am I checking the condition right? Why is it returning a NullPointer?!

ANSWER:

    if (quizDescs[0] == null) {
       mDescText.setVisibility(View.INVISIBLE);
    } else {
       mDescText.setText(quizDescs[0]);
    }


Updated on 19-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By