双重链表上的Java迭代器

时间:2022-09-05 18:51:02

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.

嗨,我对Java很新,并且在为双向链接列表构建嵌套的Iterator类时遇到了这个问题。运行测试程序时,我在E next方法上遇到此错误。迭代器中下一个方法的目标是返回双链接列表中的下一个项目。

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)

dlinkedlist.Deque中的线程“main”java.lang.NullPointerException中的异常$ 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 个解决方案

#1


It seems your current object is null. Can you check it?

看来你当前的对象是null。你能检查一下吗?

#1


It seems your current object is null. Can you check it?

看来你当前的对象是null。你能检查一下吗?