Java: Windows terminal isn't updating classes?
Alright. This isn't as much of a code problem as it is a Windows problem.
I'm using two machines at this very moment: One Linux and one Windows. I suppose that's irrelevant, but still.
OK, I put the source files for my program on both machines and am trying to run them through the command terminal.
Linux is running fine. It's busy sorting through a million integers right now. >_>
Windows... isn't. Compiling the source code doesn't update the class definitions for some reason, even when clearing all source code files from the folder I was using. What happens is that when I run the class (here, Assign1), it's running old code that I'd compiled before completely finishing my file. How I know is that it's outputting test strings that I'd removed since then.
Are the class definitions saved somewhere else besides the directory of the source code?
Re: Java: FileWriter sucks.
outFile doesn't contain anything/doesn't have a proper directory.
what are you passing to printArray as outFile?
Re: Java: FileWriter sucks.
Quote:
Originally Posted by Old problem
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 {
FileWriter outputFile = new FileWriter(outFile);
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.
Re: Java: FileWriter sucks.
Quote:
Originally Posted by
Jedward
A string.
... well, obviously
The null pointer exception on that line means you didn't pass it a proper file directory. It had nowhere to create a FileWriter. I was asking what that string was.
but you fixed it, so that's good.