File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes null pointerException handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "null pointerException handling" Watch "null pointerException handling" New topic

null pointerException handling

craig long

Joined: Jan 19, 2010
Posts: 7
I am new to java and am doing self study using Lawrenceville press Guide to Java. In this last exercise I am working on, the classes compile fine but I am getting a nullpointer error referencing the lines - "while (current.getNext() != null)" - and - "anObject.enqueue((String)entry);". I am having trouble getting around it. I have tried to handling the exceptions using throws, catch etc. but I am not setting the code up right or something in order to get the program to accept the input. What can I do to get the program to accept the user input? thank you.
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
Welcome to JavaRanch!

Please edit your post to place the code inside code tags. It makes the code much easeir to read, you can retain formatting, and will increase the chances of getting a helpful response.

When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
David Newton

Joined: Sep 29, 2008
Posts: 12617

You set current to a new node, then to head, which is null:One or both of those statements are wrong... even if head is the correct value, why set current to something only to throw it away on the next line?
craig long

Joined: Jan 19, 2010
Posts: 7
Thank you. I am not sure why I did that. Followng too close to examples in the book I guess. I removed the line and now it works great. Thank you again.
I agree. Here's the link:
subject: null pointerException handling
jQuery in Action, 3rd edition