The Artima Developer Community
Sponsored Link

Java Answers Forum
StringTokenizer problem, throwing a NullPointerException

1 reply on 1 page. Most recent reply: Mar 11, 2003 2:39 AM by Jiri Fabian

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Jesse Morrison

Posts: 2
Nickname: trueneutra
Registered: Mar, 2003

StringTokenizer problem, throwing a NullPointerException Posted: Mar 10, 2003 6:22 PM
Reply to this message Reply
Advertisement
I'm experiencing a problem using StringTokenizers. For some reason, I'm getting a NullPointerException thrown, which is odd because in other parts of my code where simular code is being executed, such problems are not popping up.

What is happening in this example is, that a line is being read that holds 3 scores for a game. The line would look like this: "|9|13|63 "
The String is tokenized, and then stored into an ArrayList.

Here's an example of what's happening:

StringTokenizer st;
String strTemp;

strTemp = in.readLine(); //Reads next line
st = new StringTokenizer(strTemp, "|"); //Tokenizes current line
while(st.hasMoreTokens()) { scoreArray.add(st.nextToken()); //adds the tokenized string to an ArrayList
}

The NullPointerException occurs Right at the line:
scoreArray.add(st.nextToken());

Does anybody have any idea why this is happening?


Jiri Fabian

Posts: 11
Nickname: filemon
Registered: Mar, 2003

Re: StringTokenizer problem, throwing a NullPointerException Posted: Mar 11, 2003 2:39 AM
Reply to this message Reply
I bet that scoreArray object is null at this time.

fil

Flat View: This topic has 1 reply on 1 page
Topic: Problem with JMF: playing .wav files Previous Topic   Next Topic Topic: Understanding of Threads in Java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use