Why am I getting Exception in Thread?
<p>I'm trying to create a simple chutes and ladders board; By having an array of objects that represent the board. I cannot figure out why I am getting three Exception in Thread errors; With the <code>setBoard</code> method, and the <code>ChutesAndLadders</code> in the <code>main</code> method. I understand that this happens because the object has a null value. However, it appears to me that I have properly initialized everything to not have a null value. </p>

<p>Here is <code>Cell</code> object that represents a space on the board,</p>

<pre><code>public class Cell {

    private String type;
    private int space;

    public Cell() {
    }

    public Cell(int m, String r) {
        this.space = m;
        this.type = r;
    }

    public void setType(String r) {
        this.type = r;
    }

    public void setSpace(int m) {
        this.space = m;
    }

    public boolean isChute() {
        return type.equals("C");
    }

    public boolean isLadder() {
        return type.equals("L");
    }

    public boolean isEmpty() {
        return type.equals("E");
    }

    public String toString() {
        return this.type + this.space;
    }

}
</code></pre>

<p>Here is the class that builds the board object,</p>

<pre><code>import java.util.Random;
public class ChutesAndLadders {

    private int numChutes;
    private int numLadders;
    private Cell[] board =  new Cell[100];
    private Random rand = new Random();

    public ChutesAndLadders() {
    }

    public ChutesAndLadders(int startChutes, int startLadders) {
        numChutes = startChutes;
        numLadders = startLadders;
        setBoard(board);
    }

    private void setBoard(Cell[] board) {

        for (int i = 0; i &lt;= board.length; i++)
            this.board[i] = new Cell(0, "E");
        makeChutes(numChutes);
        makeLadders(numLadders);
    }

    public Cell[] getBoard() {
        return board;
    }

    public void makeChutes(int n) {
        boolean cake = true;
        int rdmIntTest = 0;
        Random rndGen = new Random();

        for (int i = 0; i &lt;= n; i++) {
            int rdmInt = rndGen.nextInt(board.length);
            if ((rdmInt != rdmIntTest || cake)
                    &amp;&amp; board[rdmInt].isEmpty() == true) {
                this.board[rdmInt].setType("C");
                this.board[rdmInt].setSpace(-10);
                rdmIntTest = rdmInt;
            } else
                i--;
            cake = false;
        }
    }

    public void makeLadders(int n) {
        boolean cake = true;
        int rdmIntTest = 0;
        Random rndGen = new Random();

        for (int i = 0; i &lt;= n; i++) {
            int rdmInt = rndGen.nextInt(board.length);
            if ((rdmInt != rdmIntTest || cake)
                    &amp;&amp; board[rdmInt].isEmpty() == true) {
                this.board[rdmInt].setType("L");
                this.board[rdmInt].setSpace(10);
                rdmIntTest = rdmInt;
            } else
                i--;
            cake = false;
        }
    }

    public void printBoard() {
        System.out.println();
        int q = 0;
        int t = (int) Math.sqrt(board.length);
        for (int s = 0; s &lt; t; s++) {
            for (int i = 0; i &lt; t; i++) {
                if (board[q].isEmpty() == true)
                    System.out.print("|   |");
                else
                    System.out.print("|" + board[q].toString() + "|");
                q++;
            }
            System.out.println();
        }
    }
}
</code></pre>

<p>And here is main method,</p>

<pre><code>public class test {

    public static void main(String[] args) {

        // Create an instance of ChutesAndLadders
        ChutesAndLadders cl = new ChutesAndLadders(10, 10);

        // Randomly place 5 more chutes and 5 more ladders
        cl.makeChutes(5);
        cl.makeLadders(5);
        // Check the board and count how many chutes and how many
        // ladders were actually placed. (hint: it should be 15)
        int chutes = 0, ladders = 0;
        for (Cell cell : cl.getBoard()) {
            // check to see whether a cell is a ladder or a chute
            // and counts.
            if (cell.isLadder())
                ladders++;
            else if (cell.isChute())
                chutes++;
        }

        // print a little message and then print the board.
        System.out.println("Board has " + chutes + " chutes and " + ladders
                + " ladders");
        cl.printBoard();
    }
}
</code></pre>

<p>board is now initialized as soon as it is declared.</p>

<p>This is the read out,</p>

<p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100</p>

<p>at ChutesAndLadders.setBoard(ChutesAndLadders.java:18)</p>

<p>at ChutesAndLadders.(ChutesAndLadders.java:14)</p>

<p>at test.main(test.java:6)</p>
