Hey, I was making a program that uses the scanner class but I got a weird error. I narrowed the code down and I found the source, but I don't know how to fix it. I get the error when I try to run the program, compiling it gives me no error. My code:
Code:
import java.util.Scanner;
public class UserInput {
public static void main(String[] args) {
Scanner myInput = new Scanner(System.in);
int myNumber;
myNumber = myInput.nextInt();
}
}
Error message:
Code:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at UserInput.main(UserInput.java:6)
Tool completed with exit code 1