I'm trying to code a battleship game and im getting a weird error when i run it: Exception in thread "main" java.lang.NullPointerException at Caculations.findShip(Caculations.java:29) at Board.main(Board.java:60)
Please help im stuck and i dont know how to continue! Here is my code: (Note, its in 2 class files in my eclipse work enviorment)
public class Board {
    public static void main(String[] args) {
        boolean continuePlay = true;
        int[][] board = new int[10][10]; // creating 2d array 'board'
        char[][] boardGraphical = new char[10][10]; // creating 2d array 'board
                                                    // this time the visual
        for (int x = 0; x < 10; x++) { // for within for //initializing elements
                                        // in both boards using double for
                                        // method
            for (int y = 0; y < 10; y++) {
                board[x][y] = 0;
                boardGraphical[x][y] = 'o';
                System.out.println("Board element " + x + " " + y // printing
                                                                    // initialized
                                                                    // elements
                                                                    // here
                        + " initialized");
            }
        }
        /*
         * 1) Make user ships 1 and computer ships 2 (all numbers other than 0 =
         * true)
         * 
         * 2) Make it where if the computer gets a hit on a '1' than it sets
         * that value to like a 3 or something so it knows when the ship is
         * sunk. So in a if it does if([x][y] && [x][y])
         * System.out.println("You sunk my ship!");
         * 
         * 3) REMEMBER YOU CAN DO MULTIPLE IFS INSIDE IFS FOR MULTIPLE
         * CONDITIONS. 4) declare ships here!
         * 
         * 5) PUT STUFF IN A WHILE LOOP SO COMP CAN KEEP GOING
         */
        board[3][3] = 1; // declaring a battleship. Very important.
        board[3][4] = 1;
        board[3][5] = 1;
        boardGraphical[3][3] = 's';
        boardGraphical[3][4] = 's';
        boardGraphical[3][5] = 's';
        while (continuePlay == true) { // while loop so that computer keeps
                                        // guessing
            // WITHIN THIS LOOP KEEP REPRINTING THE BOARD
            double computerChoiceXd = Math.floor(Math.random() * 10); // using
                                                                        // Math.random
                                                                        // functions
                                                                        // for
                                                                        // computers
                                                                        // first
                                                                        // guess
                                                                        // to be
                                                                        // a
                                                                        // random
                                                                        // num
            double computerChoiceYd = Math.floor(Math.random() * 10);
            int computerChoiceX = (int) computerChoiceXd;
            int computerChoiceY = (int) computerChoiceYd;
            if (board[computerChoiceX][computerChoiceY] == 1) { // checking if
                                                                // math.random
                                                                // landed on a
                                                                // ship point
                System.out.println("Computer got a hit at " + computerChoiceX
                        + " " + computerChoiceY);
                board[computerChoiceX][computerChoiceY] = 2; // setting the
                                                                // point as 2 or
                                                                // 'hit'
                boardGraphical[computerChoiceX][computerChoiceY] = 'H';
                for (int row = 0; row < 10; row++) { // printing out graphical
                                                        // board using the same
                                                        // method as when
                                                        // intializing
                    for (int col = 0; col < 10; col++) {
                        System.out.print(boardGraphical[row][col]);
                    }
                    System.out.println(" "); // spacer for printing
                }
                Caculations test = new Caculations(computerChoiceX, // Creating
                                                                    // a new
                                                                    // object of
                                                                    // calculation
                        computerChoiceY, board);
                test.findShip();
                // break;
                if (board[3][3] == 2) { // checking to see if ship is sunk using
                                        // a triple if statement
                    if (board[3][4] == 2) {
                        if (board[3][5] == 2) {
                            System.out.println("Battleship sunk!");
                            continuePlay = false; // if so than it breaks out of
                                                    // loop to end the game
                            break;
                        }
                    }
                }
            } else if (board[computerChoiceX][computerChoiceY] == 0) { // otherwise
                                                                        // if
                                                                        // the
                                                                        // area
                                                                        // is a
                                                                        // 0 or
                                                                        // 'unmarked'
                System.out.println("Computer missed  at " + computerChoiceX
                        + " " + computerChoiceY);
                boardGraphical[computerChoiceX][computerChoiceY] = 'x'; // mark
                                                                        // area
                                                                        // as a
                                                                        // miss
                for (int row = 0; row < 10; row++) { // print out board
                    for (int col = 0; col < 10; col++) {
                        System.out.print(boardGraphical[row][col]);
                    }
                    System.out.println(" ");
                }
            }
        }
    }
}
public class Caculations {
    int xValue;
    int yValue;
    int[][] myArray;
    int[][] storage = new int[10][10];
    boolean xAxisChangeP;
    boolean yAxisChangeP;
    boolean xAxisChangeN;
    boolean yAxisChangeN;
    boolean notSunk;
    Caculations(int x, int y, int[][] myArray) {
        xValue = x;
        yValue = y;
        xAxisChangeP = true;
        yAxisChangeP = true;
        xAxisChangeN = true;
        yAxisChangeN = true;
        notSunk = true;
    }
    void findShip() {
        while (notSunk == true) {
            // 1
            while (xAxisChangeP == true) {
                if (myArray[xValue + 1][yValue] == 1) {
                    myArray[xValue + 1][yValue] = 2;
                    if (myArray[3][3] == 2) {
                        if (myArray[3][4] == 2) {
                            if (myArray[3][5] == 2) {
                                System.out.println("Battleship sunk!");
                                notSunk = false;
                            }
                        }
                    }
                    continue;
                }
                else {
                    xAxisChangeP = false;
                }
            }
            while (xAxisChangeN == true) {
                if (myArray[xValue - 1][yValue] == 1) {
                    myArray[xValue - 1][yValue] = 2;
                    if (myArray[3][3] == 2) {
                        if (myArray[3][4] == 2) {
                            if (myArray[3][5] == 2) {
                                System.out.println("Battleship sunk!");
                                notSunk = false;
                            }
                        }
                    }
                    continue;
                }
                else {
                    xAxisChangeN = false;
                }
            }
            // 1
            while (yAxisChangeP == true) {
                if (myArray[xValue][yValue + 1] == 1) {
                    myArray[xValue][yValue + 1] = 2;
                    if (myArray[3][3] == 2) {
                        if (myArray[3][4] == 2) {
                            if (myArray[3][5] == 2) {
                                System.out.println("Battleship sunk!");
                                notSunk = false;
                            }
                        }
                    }
                    continue;
                }
                else {
                    yAxisChangeP = false;
                }
            }
            while (yAxisChangeN == true) {
                if (myArray[xValue][yValue - 1] == 1) {
                    myArray[xValue][yValue - 1] = 2;
                    if (myArray[3][3] == 2) {
                        if (myArray[3][4] == 2) {
                            if (myArray[3][5] == 2) {
                                System.out.println("Battleship sunk!");
                                notSunk = false;
                            }
                        }
                    }
                    continue;
                }
                else {
                    yAxisChangeN = false;
                }
            }
        }
    }
}
 
     
     
    