I'm writing an indexOf method for a class called BasicArrayList.
i have two private instance variables an Object[] called list, and an int called size.
public int indexOf(Object element)
67 {
68 for(int i = 0; i < size; i++)
69 {
70 if(list[i].equals(element))
71 {
72 return i;
73 }
74 }
75
76 return -1;
77 }
it keeps telling me i have a null pointer exception.. but i dont know how else to change up the code. i need to use the equals method as well.
in this case i thought the method should do this: Using the provided element's equals method, this method returns the index of the first element in the list that is equal to the provided element, if any.
Thanks again for your help. Its much appreciated.