问题
Hi I'm very new to Java and have this problem with building a nested Iterator class for a Doubly Linked List. I'm getting this error on E next method when running the test program. The goal of the next method in the Iterator is to return the next item in the Doubly Linked List.
Can anyone advice a fix on my code? Any help is greatly appreciated!
Error message:
Exception in thread "main" java.lang.NullPointerException at dlinkedlist.Deque$DoubleListIterator.next(Deque.java:51)
public E next() {
if (!hasNext()) throw new NoSuchElementException();
last = current;
E value = current.item;
current = current.next;
index++;
return value;
}
public void remove() { throw new UnsupportedOperationException(); }
}// end class ListIterator
回答1:
It seems your current
object is null. Can you check it?
来源:https://stackoverflow.com/questions/30023620/java-iterator-on-doubly-linked-list