I have a problem while I'm trying to put an array of Strings on the Node of the LinkedList and this is the code which I have used.
public class Node {
public Node next ;
public String[] data;
public Node (Node next ) {
this.next = next ;
this.data = new String[6];
}
}
This is the add function to add the array inside the Node
of the LinkedList
:
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];
}
}
Error: Exception in thread "main" java.lang.NullPointerException