Java Scanner.nextInt()似乎没有任何理由抛出NoTouchElementException
代码: 此循环第一次工作,但在所选方法返回后,一旦到达nextInt(),它将抛出NoSuchElementException。其中一种方法的内部(它们几乎都是一样的)Java Scanner.nextInt()似乎没有任何理由抛出NoTouchElementException,java,java.util.scanner,Java,Java.util.scanner,代码: 此循环第一次工作,但在所选方法返回后,一旦到达nextInt(),它将抛出NoSuchElementException。其中一种方法的内部(它们几乎都是一样的) 它基本上是一个子菜单。如果我跳过开关块,循环工作正常,因此我假设这一定是子菜单中出现的问题。有什么想法吗?您在子菜单上采取的导致错误发生的操作是什么?您的代码工作正常。我不明白这个问题。你是不是在第一次进入时意外地按了两次回车键?您可以检查用户是否输入了整数,如果不是,请让他再试一次。 public static void ma
它基本上是一个子菜单。如果我跳过开关块,循环工作正常,因此我假设这一定是子菜单中出现的问题。有什么想法吗?您在子菜单上采取的导致错误发生的操作是什么?您的代码工作正常。我不明白这个问题。你是不是在第一次进入时意外地按了两次回车键?您可以检查用户是否输入了整数,如果不是,请让他再试一次。
public static void main(String args[]){
DBConnectionPool.ConnectionPool();
int scelta = 0;
Scanner sc = new Scanner(System.in);
for(;;) {
System.out.println("Selezionare il tipo di operazione da eseguire:");
System.out.println("1: Inserimento");
System.out.println("2: Modifica");
System.out.println("3: Cancellazione");
System.out.println("4: Altre");
System.out.println("5: Liste");
System.out.println("98: TEST");
System.out.println("99: Esci");
scelta = sc.nextInt();
sc.nextLine();
switch (scelta) {
case 1: opInserimento(sc);
break;
case 2: opModifica(sc);
break;
case 3: opCancella(sc);
break;
case 4: altreOp(sc);
break;
case 5: liste(sc);
break;
case 98: testSuite.testStart();
case 99:
System.out.println("Uscita");
sc.close();
return;
}
}
}
static private void opInserimento(Scanner sc) {
int selezione = 0;
System.out.println("Selezionare l'operazione: ");
System.out.println("1: Inserisci allievo");
System.out.println("2: Inserisci corso");
System.out.println("3: Inserisci esame");
System.out.println("4: Inserisci gara");
System.out.println("5: Inserisci istruttore");
System.out.println("6: Inserisci lezione");
System.out.println("7: Inserisci sede");
System.out.println("8: Inserisci numero di telefono di un allievo");
System.out.println("9: Inserisci numero di telefono di un'istruttore");
System.out.println("99: Indietro");
selezione = sc.nextInt();
sc.nextLine();
switch(selezione) {
case 1: QueryInserimento.inserireAllievo();
break;
case 2: QueryInserimento.inserireCorso();
break;
case 3: QueryInserimento.inserireEsame();
break;
case 4: QueryInserimento.inserireGara();
break;
case 5: QueryInserimento.inserireIstruttore();
break;
case 6: QueryInserimento.inserireLezione();
break;
case 7: QueryInserimento.inserireSede();
break;
case 8: QueryUtenti.aggiungiTelefonoAllievo();
break;
case 9: QueryUtenti.aggiungiTelefonoIstruttore();
break;
case 99: return;
}
}