문제

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