1

I have a problem with this method:

public void runTransaction(){
   //Some calculations...
   wait();
   //Other calculations...
}

private static void wait(){
   try {
        System.out.println("Press <enter> to continue");
        System.in.read();
    } 
    catch (java.io.IOException ex) {
        System.out.println("Input error...");
    }
}

but the programm does not continue after pressing Enter. I'm using Ubuntu 12.04.

EDIT: the programm does print the message "Press to continue" but does not continue after that, it just waits for input.

user3019653
  • 465
  • 1
  • 4
  • 7

3 Answers3

0

Does your code even compile? The wait method is public on the Object class, thus it can not be overridden as private. Try using a different method name, say waitForInput.

MarkOfHall
  • 3,334
  • 1
  • 26
  • 30
0

This shouldn't even compile:

  1. in.read() can throw an IOException, which you need to handle. (EDIT: Looks like you fixed this issue in your snippet.)

  2. You can't name this method wait() since that hides Object's wait().

Once these errors are corrected, the code should work as expected.

arshajii
  • 127,459
  • 24
  • 238
  • 287
0

Your code should run as expected if you have changed the name to wait_enter, you just need to make sure that you have clicked into the console before pressing enter so it registers the enter.

LadyDi
  • 15
  • 6