Question

I have local String array and i try to fill it with the returned tokens from Stringtokenizer.nexttoken

when i was declaring the string array as local variable i got i warning

Null pointer access: The variable words can only be null at this location

so i make the sting array as field in the class and i instantiate it

like this

 String[] words =new String [12000];

the warning disappear but i still get the same exception

StringTokenizer st=new StringTokenizer(text);


int j=0;
while(st.hasMoreTokens())
{
  words[j++]=st.nextToken();    

}

i use callable and future to execute the part of code that contain this block

and the exception that i get it is

java.lang.NullPointerException
java.util.concurrent.ExecutionException:

{the code work perfectly when i use split method to get the tokens array}

Was it helpful?

Solution

My problem fixed but replacing the String array with the arraylist<String>

while(st.hasMoreTokens())
    {
     words.add(st.nextToken()); 

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top