我是Java新手。當(dāng)我嘗試初始化時(shí)Node,發(fā)生錯(cuò)誤。這是我的代碼: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有人可以幫我嗎!
初始化節(jié)點(diǎn)錯(cuò)誤
胡說(shuō)叔叔
2021-05-13 14:08:54