I'm working on solving towers game by using stacks and linked lists and moving blocks from tower to tower by using recursion.
I encountered a problem in my problem which causes java.lang.NullPointerException. My guess why this was happening was that I try to pop value from a stack even when there are no entries. After I put bound control I still receive that error.
Th error points to the line with deleteFirst() method but I don't see why this would happens even after I check if lists are empty.
My task here was just to pass towers or LinkedStack objects then move the content of theirs in tower game fashion.
Errors:
Exception in thread "main" java.lang.NullPointerException
at LinkList.deleteFirst(towers.java:47) // code with: **first = first.next;**
at LinkedStack.pop(towers.java:82) // code with: return theList.deleteFirst();
at LinkListApp.doTowers(towers.java:146) // code with: A.pop();
at LinkListApp.doTowers(towers.java:140) // doTowers(a-1, A, C, B);
at LinkListApp.main(towers.java:121) // doTowers(nDisks, linkA, linkB, linkC);
What am I doing wrong here? I can't make this work. as it should.