I have a method called public int getSize() , and it should return the number of elements in the list. private Listable[] items; variable variable private Listable[] items; I thought it would be something like this:
int size = 0; for (int i = 0; i < items.length; i++){ size++; } return size;
But when I run it through these tests, I get this nullpointer exception in the for (int i = 0; i < items.length; i++){ line for (int i = 0; i < items.length; i++){
I do not think that he somehow likes items.length . I am not getting any errors in Java. How can I do it?
I already tried returning items.length;
which didn't work either.
source share