【发布时间】:2018-12-20 10:57:55
【问题描述】:
我在尝试将字符串数组放在 LinkedList 的节点上时遇到问题,这是我使用的代码。
public class Node {
public Node next ;
public String[] data;
public Node (Node next ) {
this.next = next ;
this.data = new String[6];
}
}
这是在LinkedList的Node内添加数组的add函数:
public void add() {
Node current = head;
if (head == null) {
for (int i = 0; i < 6; i++) {
head.data[i] = numData[i];
}
} else
while (current != null) {
current = current.next;
}
for (int i = 0; i < 6; i++) {
current.data[i] = numData[i];
}
}
错误:线程“主”java.lang.NullPointerException 中的异常
【问题讨论】:
标签: java linked-list nodes