Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java: Windows terminal isn't updating classes?
#1
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?
Reply
#2
outFile doesn't contain anything/doesn't have a proper directory.

what are you passing to printArray as outFile?
Reply
#3
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.
Reply
#4
Jedward Wrote: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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)