• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

StringTokenizer Class

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic