• Post Reply Bookmark Topic Watch Topic
  • New Topic

Linked List exception?  RSS feed

 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I created a linked list thanks to Aaron from stackOverflow and previous workings with them when I was learning c++

anyway the linkedlist works and does what I want it to do,but when the list finished running I get a null pointer exception,why is this happening and how to fix it?

Exception in thread "main" java.lang.NullPointerException
at linkedList.printList(linkedList.java:20)
at Main.main(Main.java:13)






 
Ryan McGuire
Ranch Hand
Posts: 1143
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the stopping condition for your while() loop?  What has to happen to make the loop exit?
 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan McGuire wrote:What is the stopping condition for your while() loop?  What has to happen to make the loop exit?



while current is not = to null
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Chalkley wrote:while current is not = to null


Take a look at your code again. That is *not* what the code is saying.

Henry
 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Adam Chalkley wrote:while current is not = to null


Take a look at your code again. That is *not* what the code is saying.

Henry



Thanks Henry I liked the pun =) helped a lot been coding for hours today trying to get as much practice in as possible no wonder I didn't spot that
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is tempting to spend all one's time coding frantically, but that is probably neiher a good way to code nor a good way to learn. You will probably have more success by taking things a bit easier.
Another thing: please give us more details. If you had printed the stack trace from your terminal, it would have made it faster to find the error. You can copy and paste terminal output with a process similar to that in this link.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!