I'm having some bother with a string array in java. I'm trying to output an inverseNewWords LinkedHashMap value to an output file, but I keep getting an NPE for the array. For some reason the first line doesn't seem to work.

System.out.println(inverseNewWords.get(codeIntegers[i]));

prints out the word fine, but this line:

System.out.println(newWTF[i]);

comes back as null.

newWTF[i] = inverseNewWords.get(codeIntegers[i]);
System.out.println(inverseNewWords.get(codeIntegers[i]));
System.out.println(newWTF[i]);
decodedWriter.write(newWTF[i]);

** EDIT ** Thanks for the quick replies, I've been working on this specific program throughout the night to get it submitted on time, and my head's cracked. The string array was indeed initialized incorrectly, but now my main problem is showing it's face:

System.out.println(newWTF[i]);
decodedWriter.write(newWTF[i]); 

the println statement correctly shows me each word in the array. However, the FileWriter isn't writing the same words to the file. (The Filewriter is being flushed and closed before the program ends) Any help is greatly appreciated

有帮助吗?

解决方案

The only reason why this line

System.out.println(newWTF[i]);

can throw NPE is that newWTF is null

其他提示

may help :

newWTF = new String[inverseNewWords.size()];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top