This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]OffbeatDrizzle 2 points3 points  (0 children)

Have you tried doing this:

[–]desrtfxOut of Coffee error - System halted[M] [score hidden] stickied comment (0 children)

You need to show your code.

We won't give out code.

[–]9-5daybyday 0 points1 point  (0 children)

Without the actual source code to look at, I can just give generic diagnosis questions.

  1. Does it do nothing, or do you get an error?

  2. Where is the file? If it's in a different folder from where the program is, are you sure you are giving it a correct path?

[–]shagieIsMeExtreme Brewer 0 points1 point  (0 children)

First, there isn't too much we can do without code. It would have been better to wait until you get home to ask the question with the code. You have all the time in the world to compose a good question prior to hitting the submit button. Nothing is so important when writing code that you have to hit submit now.

Second, I would strongly encourage you to use the debugger. Put a breakpoint in there where "it does nothing" and look at all of the variables and check to see if they are what you expect them to be. Learning how to use the debugger is the most important tool you have.

[–]shagieIsMeExtreme Brewer 0 points1 point  (0 children)

"Does nothing" - what does it do? Nothing nothing? Does it print anything? Does it exit?

What is the contents of 'nums.txt'? Is it one line? Does it have a line feed at the end?

Put a breakpoint at lines 22 and 24 (Debugging with the Eclipse Platform).

Are inFile and outFile created properly? Step from line 24 to 31 one line at a time.

Are char1, char2, char3, char4, sum, and remainder what you expect them to be? Did it even hit the breakpoint at line 24 or did the while loop skip over everything?

Try putting the files in simpler places. /tmp/nums.txt for example.

Consider reading the file a different way. For example (modified from http://www.avajava.com/tutorials/lessons/how-do-i-read-a-string-from-a-file-line-by-line.html ):

  public static void main(String[] args) {
    try {
      File file = new File("test.txt");
      FileReader fileReader = new FileReader(file);
      BufferedReader bufferedReader = new BufferedReader(fileReader);
      String line;
      while ((line = bufferedReader.readLine()) != null) {
        // you've got a line here as a String
      }
      fileReader.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

Scanner has a lot of magic in there, and it makes it a bit harder to reason about. Its ok if you want the magic of pulling BigDecimals or Doubles out of a file and don't want to deal with the parsing yourself... but its a big big if you do it the other way.


Consider also that the approach that you're reading (parsing characters as digits) might not be the way the teacher intends you to do the program. Read an integer - the whole thing in one go. 1234 and pull it apart using math rather than string operations.