I have the following code:
while (true) {
if (flag == 0) {
System.out.println("1. Display all staff");
System.out.println("2. Clear schedule");
System.out.println("3. Display schedule");
System.out.println("4. Assign shift to casual employee");
System.out.println("5. Assign shifts to permanent employee");
System.out.println("6. Calculate total weekly wages");
System.out.println("7. Exit Program");
while (true) {
System.out.println("Enter your selection");
Scanner in = new Scanner(System.in); // in these lines
n = in.nextInt(); // in these lines
if (n <= 0 || n > 7) {
System.out.println("Invalid Selection - must be between 1 and 7.");
break;
}
}
}
Now, whenever I run the program, it gives me the following compilation error:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at EmployeeDriverSystem.main(Main.java:61)
Line 61 is the line with the comment "in these lines"