它在 do-while 循环内的第三行崩溃,并且不等待我的输入:
input = kb.nextInt();
堆栈跟踪:
线程“主”java.util.NoSuchElementException 中的异常
在 java.util.Scanner.throwFor(未知来源)
在 java.util.Scanner.next(未知来源)
在 java.util.Scanner.nextInt(未知来源)
在 java.util.Scanner.nextInt(未知来源)
在 main.MainDriver.main(MainDriver.java:50)
相关代码:
do
{
displayFullMenu();
System.out.print("Selection: ");
input = kb.nextInt();
switch (input)
{
//Create new survey
case 1: currentSurvey = new Survey();
break;
//Display current survey
case 2: currentSurvey.display();
break;
//Save current survey
case 3: saveSurvey(currentSurvey);
break;
//Load a survey
case 4: currentSurvey = loadSurvey();
break;
//Modify a survey
case 5: currentSurvey.modify();
break;
/*******************Test Functions*******************/
//Create new test
case 6: currentSurvey = new Test();
break;
//Display current test
case 7: currentSurvey.display();
break;
//Save current test
case 8: saveSurvey(currentSurvey);
break;
//Load a test
case 9: currentSurvey = loadTest();
break;
//Modify a test
case 10: currentSurvey.modify();
default: System.out.println("Invalid choice. Please make a valid choice: ");
input = kb.nextInt();
System.out.println();
}
} while (input != 99);
kb.close();
在我选择选项 9 后它崩溃了。它正确保存了文件,然后返回到循环的顶部,并在前面提到的行处崩溃。我希望它要求更多的输入。
是什么赋予了?