我是Java新手。当我尝试初始化时Node,发生错误。这是我的代码:
class Node {
int data;
Node next;
Node(int d) {data = d; next = null; }
}
public class RemoveDups {
public static void main(String[] args) {
// TODO Auto-generated method stub
Node head=new Node(0);
Node node=head.next;
for(int i=0;i<20;i++) {
node=new Node(i);
node=node.next;
}
node=head;
while(node!=null){
System.out.print(node.data);
node=node.next;
}
}}
我收到了NullPointerException。
Exception in thread "main" java.lang.NullPointerException
有人可以帮我吗!
相关分类