宿題のためにJavaで三目並べゲームを作成しています。TicTacToe という親クラスと、humanVsHuman という派生クラスがあります。
派生クラスには次のメソッドが記述されています。これは、ユーザーがゲーム ピース (X または O) に入りたい位置を入力するように促し、親クラスから 2 つのメソッドを呼び出します。 displayBoard() と呼ばれる新しいピースを含むボード。
メソッドは次のとおりです。
private void playGame() {
Scanner keyboard = new Scanner (System.in);
int row, col;
System.out.println("When playing, enter the row and column position for your X or O piece separated by a space.");
do{
System.out.print(player1 + ", Enter X position: ");
row = keyboard.nextInt();
col = keyboard.nextInt();
setGb(row, col, 'X');
displayBoard();
System.out.print(player2 + ", Enter O position: ");
row = keyboard.nextInt();
col = keyboard.nextInt();
setGb (row, col, 'O');
displayBoard();
keyboard.close();
} while (!gameOver());
}
次のランタイム エラーが発生します。
When playing, enter the row and column position for your X or O piece separated by a space.
Deena, Enter X position: Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at Assignment7C.HumanVsHuman.playGame(HumanVsHuman.java:38)
at Assignment7C.HumanVsHuman.repeatGame(HumanVsHuman.java:28)
at Assignment7C.HumanVsHuman.game(HumanVsHuman.java:14)
at Assignment7C.TicTacToeTest.main(TicTacToeTest.java:10)
位置を入力するプロンプトが表示されるとすぐに、位置を入力する前にエラーが発生します。
よろしくお願いします。