public class LString{
char data; //chars stored in this node
LString next; //link to next LString node
public LString(char newdata){
data = newdata;
}
public LString(char newdata, LString newnext){
data = newdata;
next = newnext;
}
public LString(){
}
//create a front of list
LString front;
//create length of list
int length;
/*Construct an LString object. The LString object will represent the
same list of chars as original. That is, the newly created LString is a
"copy" of the parameter original.*/
public LString(String original){
LString curr = front;
for(int i = 0; i < original.length(); i++){
curr.data = original.charAt(i);
curr = curr.next;
length++;
}
}
}
public class test{
public static void main(String[] args){
LString myList = new LString("hi");
}
}
The following code should put the string "hi", into a linked list of chars, where each letter of hi, is one node of the list. When ran, it gives a nullpointerexception pointing to the line curr.data = original.charAt(i);. Why is there a null pointer exception there? Thank you