• Post Reply Bookmark Topic Watch Topic
  • New Topic

StringTokenizer / NullPointerException problem  RSS feed

 
Tyler Jordan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been getting a NullPointerException during this specific section in my application. I assume that the StringTokenizer is grabbing a null value which is causing the problem, but it is my understanding that the hasMoreTokens() method should eliminate that problem. The input file that I use is a .csv file.



This is the error.

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't call hasMoreTokens until you have made at least one call to nextToken.
But what I think your problem really is, is that you don't check if 'line' is null before passing it to StringTokenizer.
 
Tyler Jordan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I'll do is add a string like EOF on the end of my classcodes file and use that as a delimiter for the end of the file. This is a little cludgy, but it will at least narrow the focus.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
line will be set to null when you reach the end of the file so why don't you use that to end your while loop
Try
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!