提问人:Jen 提问时间:1/18/2023 最后编辑:Federico klez CullocaJen 更新时间:1/18/2023 访问量:61
A NoSuchElementError
A NoSuchElementError
问:
下面的代码假设启动一个连接 4 游戏,我使用扫描仪类来获取用户的输入,但是当我运行它时,它给了我一个 NoSuchElementError。
我试图注释掉 close();方法并重新运行程序,但相同的错误很普遍。
这是我的代码。
Pick a row
Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at E.start(E.java:223)
at Main.main(Main.java:6)
public void start(){//need a method that changes the board{
while(checkPlayerWin()== false|| checkAIWin()== false){
Scanner scan= new Scanner(System.in);
System.out.print("Pick a row ");
int row= scan.nextInt();
insertCounter(row, "X");
scan.close();
reprintBoard();
random();//insert random counter into a place in the board
reprintBoard();
}
}
a.start();//in the class main on line 6
答: 暂无答案
评论
close
Scanner
true
false
while (!checkPlayerWin() || !checkAIWin())
&&
||
close()
Scanner
System.in
close()
System.in
Scanner