i'm trying to finish up the last project in our course and i cant get this part to work. it won't let me compile it and doesn't tell me the reason , other than application errors when i try to find out what the problem was. and then when i did run it, it'd give me
but the lines aren't red.1|Exception in thread "main" java.lang.NullPointerException
at Board.printBoard(Board.java:65)
at Game.playGame(Game.java:98)
at Game.main(Game.java:46)
the culprit, for the Game class:
and then i'm trying to relate it to this one: This is the Player classpublic static int playGame(int[] playerplayingCondition) { Game game = new Game(); int nextTurn = 1; //currentPlayer's assigned turn. int Result; //Result of the winningCondition, if found, no more turn. while (true) { //Everytime the current game has remaining moves left, it'll ask for the player/computer to submit move Board.printBoard(); //This just asks for the moves of the current Players, and the move is submitted each time as a turn. if (playerplayingCondition[nextTurn] == 0) { Player.getComputerMove(game, nextTurn); } else { Player.getHumanMove(game, nextTurn); } Result = getWinningConditions(); if (Result > 0) { return Result; } //If the current player turn is 1, second player it 2. Makes it so that it rotates each turn. if (nextTurn ==1){ nextTurn = 2; } else if (nextTurn ==2){ nextTurn = 1; } //If there is still no winningCondition found, returns -1. makes the turn goes looping again. } }
public static void getHumanMove(Game game, int player) { char rowChar, columnChar; int row, column; boolean acceptableAnswer; do { acceptableAnswer = true; //Initialize the boolean first as true so the loop can go. System.out.print("Please enter your move. " + "For example, " + Board.columnLegend[1] + //I just put in a random value as an example Board.rowLegend[0] + ": " ); Scanner in = new Scanner(System.in); String move = in.nextLine(); //Returns user's answer into move columnChar = move.toUpperCase().charAt(0); // columnChar is the column letter corresponding to user's answer column = Board.ValidatingMoves(columnChar, Board.columnLegend); //checks to see if the character matchValuees with the A,B,C legend rowChar = move.toUpperCase().charAt(1); //rowChar is the row number corresponding to user's answer row = Board.ValidatingMoves(rowChar, Board.rowLegend); //checks to see if the numbers matchValuees with 1,2,3 legend //Starts validation process //Makes sure that the answer is exactly 2 characters. if (move.length() <2 ||move.length() >2) { System.out.println("Must use exactly two characters"); continue; } //Checks if column is A, B, or C. //It's in numbers instead of letters because it uses the ValidatingMoves method //that returns the legend as numbers. [i][0] = A, [i][1] = B, [i][2] = C if (column < 0 || column > 2) { System.out.println("Invalid column! Use A, B, or C. "); continue; } // Check if row is 1, 2, or 3. //[0][j] = 1, [1][j] = 2, [2][j] = 3 if (row < 0 || row > 2) { System.out.println("Invalid row! Use 1, 2, or 3. "); continue; } // Checks if move is occupied //When everything else is passed, this returns false so it doesn't have to loop else { acceptableAnswer = false; } } while (acceptableAnswer !=false); } /********************************************************************* * Method Name: getComputerMove * Parameters: ticc, player * Returns: NONE * Description: It generates randomMoves for the computer *********************************************************************/ static void getComputerMove(Game game, int player){ int i, j; // row, column if (Board.findRemainingMoves()){ //Checks to see if there are moves left do { Random randomNumbers = new Random(); int move = (int)(randomNumbers.nextDouble() *9) +1; i = (move - 1)/ Board.board.length; //Makes sure the move of the array isn't out of bounds. j = (move - 1) % Board.board[i].length; } while ((Board.board[i][j] !=0)); //Making sure that it isn't on an occupied space //Submits computer's move System.out.println("Computer Moves: " + Board.columnLegend[j] + Board.rowLegend[i]); } }
and I get this: whenever I change the Player class's getMoves methods parameter into Player game instead of Game game
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method getComputerMove(Player, int) in the type Player is not applicable for the arguments (Game, int)
The method getHumanMove(Player, int) in the type Player is not applicable for the arguments (Game, int)
and the red lines appears there at getComputerMove
I also have a Board class that prints out the board but it only gives me an error whenever the Game gives me an error b/c it can't submit any moves.Player.getComputerMove(game, nextTurn); } else { Player.getHumanMove(game, nextTurn); }
It works for Procedural Programming though...like just one class but we have to now split into different classes for OOP.
Help will be appreciated