Java Iterator on doubly linked list

Hi I am very new to Java and have this problem with nested Iterator for Doubly Linked List. I am getting this error on the following method E 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 please advise to fix my code? Any help is greatly appreciated!

Error message:

Exception on thread "main" java.lang.NullPointerException on 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

      

-2


source to share


1 answer


Your object seems current

to be null. Can you check it out?



+2


source







All Articles