# "If doc == null" not is correct

**URL:** <https://discourse.processing.org/t/if-doc-null-not-is-correct/17941>\
**Category:** Beginners\
**Created:** [February 19, 2020, 7:55pm UTC](https://discourse.processing.org/t/if-doc-null-not-is-correct/17941 "2020-02-19T19:55:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)\
**Post date:** [February 19, 2020, 7:55pm UTC](https://discourse.processing.org/t/if-doc-null-not-is-correct/17941/1 "2020-02-19T19:55:34Z")

</div>

Guys, I tried to solve this problem myself, but I couldn’t.  
I have the docMain [0] line, which I take from the file on the phone, but even if it is null (checked), then the if check considers it not null anyway .  
how to solve this? The code is correct.

if(docMain[0]==null){ //if language tag not have  
println(“work hehehh”);  
specialMenuLanguageSet(); mGFocus=-4;  
}else{  
println(“not work?”);  
println(docMain[0]);  
iconLanguage=loadImage(“iconLanguage”+docMain[0]+".png"); mGFocus=0;}

---

<div class="post-metadata">

**Author:** ![bucherjo](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@bucherjo](https://discourse.processing.org/u/bucherjo)\
**Post date:** [February 19, 2020, 8:57pm UTC](https://discourse.processing.org/t/if-doc-null-not-is-correct/17941/2 "2020-02-19T20:57:21Z")

</div>

One problem could be that docMain is not properly initialized, so that the array itself is null. Therefore it is not possible to read the 0th entry, which would lead to a NullPointerException.

---

<div class="post-metadata">

**Author:** ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)\
**Post date:** [February 19, 2020, 9:19pm UTC](https://discourse.processing.org/t/if-doc-null-not-is-correct/17941/3 "2020-02-19T21:19:24Z")

</div>

I download the document like this:  
docMain = loadStrings (path + “/” + folder + “/ docMain.txt”);

And when checking (when the code goes along the else branch), null is written to me in the console, although the code does not consider it null.

What does initialization mean? How can I fix this?

---

<div class="post-metadata">

**Author:** ![bucherjo](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@bucherjo](https://discourse.processing.org/u/bucherjo)\
**Post date:** [February 19, 2020, 9:34pm UTC](https://discourse.processing.org/t/if-doc-null-not-is-correct/17941/4 "2020-02-19T21:34:35Z")

</div>

initialization is the setup of your array. You can check if an array is null (not a specific entry of the array, but the array itself) by creating a if-statement which goes as follows:

```auto
if(docMain==null){ //checks if docMain is iself null
   println("array is null");

}else if(docMain[0]!=null){ //checks if array is null at position 0
   println("entry at position 0 is "+docMain[0]);
}

```

---

<div class="post-metadata">

**Author:** ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)\
**Post date:** [February 19, 2020, 9:49pm UTC](https://discourse.processing.org/t/if-doc-null-not-is-correct/17941/6 "2020-02-19T21:49:50Z")

</div>

Text in console “entry at position 0 is”.

---

<div class="post-metadata">

**Author:** ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)\
**Post date:** [February 19, 2020, 11:05pm UTC](https://discourse.processing.org/t/if-doc-null-not-is-correct/17941/7 "2020-02-19T23:05:14Z")

</div>

Any ideas what to do?  
I have already tried changing this position in the array to some conditional “faf”, but that is not the point.

Moreover, if you install this faf after loading the document manually, then everything works.

What could be the problem?

---

<div class="post-metadata">

**Author:** ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)\
**Post date:** [February 20, 2020, 6:00am UTC](https://discourse.processing.org/t/if-doc-null-not-is-correct/17941/8 "2020-02-20T06:00:58Z")

</div>

Please help. I’m desperate.

---

<div class="post-metadata">

**Author:** ![anon68884268](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon68884268](https://discourse.processing.org/u/anon68884268)\
**Post date:** [February 20, 2020, 1:40pm UTC](https://discourse.processing.org/t/if-doc-null-not-is-correct/17941/9 "2020-02-20T13:40:31Z")

</div>

An empty string is not null. This

```auto
if(docMain[0].equals("")){ //if language tag not have
println(“work hehehh”);
specialMenuLanguageSet(); mGFocus=-4;
}else{
println(“not work?”);
println(docMain[0]);
iconLanguage=loadImage(“iconLanguage”+docMain[0]+".png"); mGFocus=0;}

```

should do the work. Comparing strings with `==` does not work because Strings are objects, and Java compares object if they point at the same object, not the same _content_

---

<div class="post-metadata">

**Author:** ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)\
**Post date:** [February 20, 2020, 2:06pm UTC](https://discourse.processing.org/t/if-doc-null-not-is-correct/17941/10 "2020-02-20T14:06:40Z")

</div>

That is, I was missing instead of == equals?  
Everything works.

YOU HELPED ME A LOT! HOW AM I SAME?  
THANKS A LOT!

---

<div class="post-metadata">

**Author:** ![anon68884268](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon68884268](https://discourse.processing.org/u/anon68884268)\
**Post date:** [February 20, 2020, 2:07pm UTC](https://discourse.processing.org/t/if-doc-null-not-is-correct/17941/11 "2020-02-20T14:07:53Z")

</div>

You’re welcome.  
Yes, it was just `equals("")`
