wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes tokenizer throwing NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "tokenizer throwing NullPointerException" Watch "tokenizer throwing NullPointerException" New topic
Author

tokenizer throwing NullPointerException

Tony Fabeets
Ranch Hand

Joined: Dec 22, 2003
Posts: 38
I'm not seeing why i'm getting a null pointer, so i'm posting my entire do{}while(). I'm taking in a file, using readLine() and tokenizing each line to the approp vars until the end of the file.

*edit* here is the revised code. i'm getting null for inputLine and tokenizer, so the problem is at inputLine = reader.readLine(), but I'm not seeing why
[ December 22, 2003: Message edited by: Tony Fabeets ]
*edit*
i am happy to say that importFile() is now working properly
thx for the help
[ December 22, 2003: Message edited by: Tony Fabeets ]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

What line are you getting the NPE on? Take a look at that line and see what variables are having methods called on them -- usually there's only one. That will tell you exactly what variable is null, and then its just a matter of figuring out why that variable is null.
Also, please use [CODE] and [/CODE] tag when posting code; it makes it much easier to read.
I note that you have a do..while loop, based on while inputLine is not null. If inputLine is null the first time through the loop, then you will more than likly get a NPE. In this instance, you probably just want a while loop. (do...while loops are generally to be avoided.)
[ December 22, 2003: Message edited by: Joel McNary ]

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Tony Fabeets
Ranch Hand

Joined: Dec 22, 2003
Posts: 38
that was a blazing fast response thank you. I'm getting it on the line
tokenizer = reader.readline(inputLine," ");
been trying to run the bluej debugger, but it only runs upto the creation of the gui. debugger won't look into input file. I'm still pretty new to java, so i'm probably overlooking something simple.
*edit* found that inputLine is null, but why?
*edit* I took out the call to main.lineCnt() and that took care of the null pointer i was getting on reader.readLine();
now i'm getting an elementNotFound exception
[ December 22, 2003: Message edited by: Tony Fabeets ]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Well, not to belabor the obvious, but does your input file have anything in it?
Also, you should want a { ... } after your while, not a ; I don't think that this is what you are wanting.
Tony Fabeets
Ranch Hand

Joined: Dec 22, 2003
Posts: 38
when editing the post, the ";" was a typo. As edited in the previous post, i worked the bugs out... only to find that each objects variables are 0...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: tokenizer throwing NullPointerException