title: java Scanner force user to input a int value
body: <pre><code>public class Main{
      public static void main(String args[]){
      int i = nextInt();
  }
  public int nextInt(){
      int i=0;
      boolean done=false;
      Scanner scanner = new Scanner(System.in);
      while (!scanner.hasNextInt()){
              scanner.nextLine();
          Printer.println(Printer.PLEASE_NUMBER);
      }
      i=scanner.nextInt();
      scanner.close();
      return i;
  }
  }
  </code></pre>
  
  <p>The code above is how I'm trying to force a user to input a int value, but I get the nosuchelement exception, as the scanner.nextLine() reads a NULL. 
  In c++ the software waits for the user to input something. Is there anything I can do to force the program to stop, wait for the user to input something and then make the check?</p>
  
  <p>EDIT:
  So I'm having problems regardless, if I use scanner outside of Main class, it gives that error... </p>