Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tokenizer throwing NullPointerException

 
Tony Fabeets
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Tony Fabeets
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic