I've been reading about issues with Scanner, but even after adding in an extra in.nextLine()
or in.nextInt()
all Java does is move the NoSuchElementException
up to that line. Any suggestions? I'm trying to create an auto-looping menu selection for my program. Every time it loops case 1, it has an issue.
while (!done) {
System.out.println("Welcome, please type a number for selecting from the following: \n 1. Insert Process \n 2. Print out a list of processes \n 3. See and remove first priority process \n 4. Quit");
Scanner in = new Scanner(System.in);
int selector = 0;
print(); in .nextLine();
selector = in .nextInt();
switch (selector) {
case 1:
System.out.println("Please enter a priority for the new process > 0");
Scanner pin = new Scanner(System.in);
priority = pin.nextInt();
if (priority > 0) {
maxHeapInsert(priority); //allows user to set priority
in .close(); in = new Scanner(System.in);
break;
} else {
System.out.println("ERROR, you did not enter a number greater than 0");
}
break;
}
}