I am attempting to add a node to the end of my linked list, i get a null pointer exception when i get to the else statement and try to set problem.rear.next to the new node I am adding. For some reason when i attempt to set the rear.next pointer to a new node the exception pops up.
To clarify,
The BigIntegerList is a linked list of nodes which are also linked lists that represent a Big integer by linking individual integers together. The big integer list defines a "start" and "rear" node, The BigInteger node defines "x" for the data and "next" for a pointer to the next node in the list.
Also,
problem.n represents the number of BigIntegers to be read in, the method reads from a text file, the first number read states how many big integers are going to be read followed by the actual BigIntegers
Any ideas welcome as I am very stuck....
BigIntegerList problem;
LinkedList x;
BigIntegerNode curr;
problem = new BigIntegerList();
//get value of first line stating #of bigInts to read in
problem.n = LinkedList.readInteger(in);
//read big ints from text file based on first number passed, n
for(int i=0; i<problem.n;i++)
{
x = new LinkedList();
x.readBigInteger(in);
//case that the list is empty
if(problem.n<1)
{
problem.start = new BigIntegerNode(x,null);
problem.rear = problem.start;
//list is not empty, add nodes to rear
}else
{
curr = new BigIntegerNode(x,null);
problem.rear.next = curr; -----> this is where i get a nullpointer....
problem.rear = curr;
}
}
return problem;