---
title: "!array[0].isEmpty() returning NullPointer?"  
description: "!array[0].isEmpty() returning NullPointer?"  
author: "Anonymous User"  
published: 2014-11-18  
updated: 2014-11-19  
canonical: https://www.mindstick.com/forum/12634/array-0-isempty-returning-nullpointer  
category: "android"  
tags: ["java", "nullpointerexception"]  
reading_time: 1 minute  

---

# !array[0].isEmpty() returning NullPointer?

Here's my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

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

So, when this code [runs](https://answers.mindstick.com/qa/48615/when-was-the-runs-in-ruins-written), and the if [condition](https://www.mindstick.com/forum/12711/select-query-with-and-condition) returns [true](https://yourviews.mindstick.com/view/81326/boycott-chinese-products-dream-will-come-true), everything is fine and dandy, however, if it returns false, it says there's a [NullPointerException](https://www.mindstick.com/forum/159415/an-android-app-crashes-with-a-nullpointerexception), and points me to the line of code containing the [if statement](https://www.mindstick.com/forum/12682/jquery-toggle-if-statement).

Am I checking the condition [right](https://www.mindstick.com/articles/12766/check-whether-you-are-doing-digital-transformation-right-or-not)? Why is it [returning](https://www.mindstick.com/news/2477/returning-ceo-bob-iger-dismisses-the-disney-apple-sale-as-pure-speculation) a NullPointer?!

**ANSWER:**

```
    if (quizDescs[0] == null) {       mDescText.setVisibility(View.INVISIBLE);    } else {       mDescText.setText(quizDescs[0]);    }
```

## Replies

### Reply by Tom Cruser

if quizDesc[0] is String, you can do

```
if(!StringUtility.isEmptyOrNull(quizDesc[0])){ mDescText.setText(quizDescs[0]);}else {    mDescText.setVisibility(View.INVISIBLE);}
```

By the way, Null and being empty is not same

Consider

```
String s; //Initialize to nullString a =""; //A blank stringIts always a good practise to usetry{   //Your code here..}catch(Exception e){    e.printStacktrace();}
```


---

Original Source: https://www.mindstick.com/forum/12634/array-0-isempty-returning-nullpointer

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
