Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StringTokenizer Class

 
DANIEL GRESHAM
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im using a string tokenizer in my current class project, because I'm required too. heres the error message I am getting when I try and test the StringTokenizer,

I have no idea what any of this means, but here is my actual code so that maybe someone can point me in the direction of what I'm doing wrong thus far, because my text book is of no help, neither is my professor, because hes on springbreak.
well here it is and thanks for any help in advance.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The init mentioned in the stack trace is a part of the constructor process. The null error probably means one of your arguments to new StringTokenizer was null. I didn't try to find where the arguments come from in your code, but you may need to edit the user's input or provide default values. Hope that helps!
 
DANIEL GRESHAM
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah I think I figured it out, will the program run into any more errors if I move the "new" StringTokenizer from the constructor to the spot where I'm using it?
 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that the StringTokenizer instance is tokenizing on the String "input". But since "input" is an instance variable intialized to null, the constructor attempts to tokenize "input", i.e. its tokenizing "null" which is why you get the NullPointerException. You should move the tokenizing out of the constructor because this constructor is called in the main() method where you create an instance of the class. However, at this point *(in your main method), "input" has not changed and is still null, and your constructor will being working on this variable even before you get input from the user.
[ March 12, 2005: Message edited by: Kashif Riaz ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic