I have the following code and i get Null pointer exception at this line: unWanted[g].equals("")
I dont know how can it be because i check before that if unWanted isnt null. Thank for helping :)
public String[] setExercies(){
DataBaseMain data = new DataBaseMain(this);
data.open();
String[] unWanted = data.getAllUnwantedExercies();
String[] exits = data.getAllExercies();
data.close();
if(unWanted == null)
return exits;
int f = 0;
for(int g = 0; g < unWanted.length; g++)
{
if(unWanted[g].equals(""))
f++;
}
String[] temp = new String[unWanted.length-f];
f = 0;
for (int k = 0; k < unWanted.length; k++){
if(unWanted[k].equals("") == false)
{
temp[f] = unWanted[k];
f++;
}
}
unWanted[g]
isnull
at some value ofg
. Do anull
check before applying theequals
. – Luiggi Mendoza May 10 '13 at 16:34blam.equals("hoot")
which will throw an NPE if blam is null, use"hoot".equals(blam)
which wil lnever throw an NPE. – DwB May 10 '13 at 16:45