2013-02-04, 08:58 PM
Old problem Wrote:Okay, so I have a method that writes the content of an integer array to a file, one per line. This is part of a bigger class, but I can confirm that everything works except for this last method.
The exception that Java throws is a NullPointerException, so.. y'know. Null pointer.
Here's the relevant code:
Code:import java.io.FileWriter;
import java.io.IOException;
...
private static void printArray(int[] arr, String outFile){
try {
[U]FileWriter outputFile = new FileWriter(outFile);[/U]
for(int i = 0; i < arr.length; i++){
String intWriter = Integer.toString(arr[i]);
outputFile.write(intWriter + "\n");
}
outputFile.close();
System.out.println("Successsfully written " + outFile + "\n");
}
catch(IOException ex){
ex.printStackTrace();
}
}
I honestly don't know what's wrong here and it's pissing me off.
EDIT: The exact line that gives the exception is underlined now.
outFile is a string. Of course.
Fixed it: string wasn't being initialized correctly and was returning a null value.
See post 1 for new problem.

