"If doc == null" not is correct

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;}

1 Like

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.

1 Like

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?

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:

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]);
}
2 Likes

Text in console “entry at position 0 is”.

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?

Please help. I’m desperate.

An empty string is not null. This

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

2 Likes

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

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

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

1 Like