Вопрос

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