I have a partially nfilled array of objects, and when I iterate through them I tried to check to see whether the selected object is null
before I do other stuff with it. However, even the act of checking if it is null
seem to through a NullPointerException
. array.length
will include all null
elements as well. How do you go about checking for null
elements in an array? For example in the following code will throw an NPE for me.
Object[][] someArray = new Object[5][];
for (int i=0; i<=someArray.length-1; i++) {
if (someArray[i]!=null) { //do something
}
}