I have
public Object get(int index)
{
if (index <= 0)
return null;
Node Current = head.getNext();
for (int i = 1; i < index; i++) {
if (Current.getNext() == null)
return null;
Current = Current.getNext();
}
return Current.getData();
}
this method for a linked list to get something in an index. That something is a Painting object, and I want to get the title of the painting using a getTitle method within the Painting class.
Here is what I tried to do,
for(int i = 0; i < paintings.size(); i++){
Painting x = (Painting) paintings.get(i);
System.out.println((i+1) + ": " + x.getTitle());
}
Unfortunately at x.getTitle() java gets extremely salty and gives a null pointer exception. I've tried multiple ways of doing this with different casts and I'm just personally lost. Any help would be deeply appreciated.