我得到了以下代码,但是在第一个循环之后,我的调试器给出了以下错误,这很奇怪,我一直那样做,但是它不再起作用了,这很奇怪吗?我一步一步检查,切换命令后只是停顿了吗?Exception in thread "main" java.lang.IllegalStateException: Scanner closed at java.util.Scanner.ensureOpen(Unknown Source) at java.util.Scanner.findWithinHorizon(Unknown Source) at java.util.Scanner.nextLine(Unknown Source) at Level.schleife(Level.java:35) at Crawler.main(Crawler.java:23)public boolean schleife() { System.out.println("Das Spiel beginnt, bewege Dich mit der WASD Steuerung!"); Scanner eingabeMove = new Scanner(System.in); tmpi = positioni; tmpj = positionj; while (true) { String bewegung = eingabeMove.nextLine(); switch (bewegung) { case "w": { // vorwärts tmpi += 1; if (actionResult()) { positioni = tmpi; break; } else { return false; } } case "a": { // links tmpj -= 1; if (actionResult()) { positionj = tmpj; break; } else { return false; } } case "s": { // rückwärts tmpi -= 1; if (actionResult()) { positioni = tmpi; break; } else { return false; } } case "d": { // rechts tmpj += 1; if (actionResult()) { positionj = tmpj; break; } else { return false; } }}
添加回答
举报
0/150
提交
取消