aspose file tools
The moose likes Java in General and the fly likes StringTokenizer / NullPointerException problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "StringTokenizer / NullPointerException problem" Watch "StringTokenizer / NullPointerException problem" New topic
Author

StringTokenizer / NullPointerException problem

Tyler Jordan
Ranch Hand

Joined: Nov 17, 2003
Posts: 70
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

Joined: Aug 05, 2005
Posts: 3011
    
    9
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.


Joanne
Tyler Jordan
Ranch Hand

Joined: Nov 17, 2003
Posts: 70
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

Joined: Aug 05, 2005
Posts: 3011
    
    9
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StringTokenizer / NullPointerException problem
 
Similar Threads
inserted data lost!
Need help with NullPointerException
reading an CSV file
Parsing notepad content separated by pipes
Re: FileWriter write operation