双重链表上的Java迭代器 [英] Java Iterator on doubly linked list

查看:307
本文介绍了双重链表上的Java迭代器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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!

错误消息:


线程中的异常主要的 java.lang.NullPointerException at
dlinkedlist.Deque $ DoubleListIterator.next(Deque.java:51)

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


推荐答案

您的当前对象似乎为空。你能检查一下吗?

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

这篇关于双重链表上的Java迭代器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆