Ok, i have been making a chess game program, basically what it is is a chesspiece class and a chess board class, the chessboard class has an 8x8 2-d array of chesspiece objects, then i have my frame, my frame has a parallel 2-d array of Jtoggle buttons, when a user clicks on a square a method in my chessboard class (using a location class which just stores row num and col num) returns an array of possible moves, every button on my frame uses a private method to enable and highlight all possible move spaces. However, when i run the program, i clikc on button with a pawn and nothing happens, all it does is freeze and stop running, then it says java heap error, or out of memory, and closes the current run. Plase help!

Recommended Answers

All 4 Replies

You are probably getting into an infinite loop or recursion that creates a lot of new objects until it's out of heap space. Check your loop conditions or recursive calls and make sure they are terminating as they should.

ok i fixed the heap error but now im gettign an array out of bounds error -1

with this code

//down 1 and left 1
            for (int r = row; row < 8; r++)
            {
                for (int c = column; c > -1; c--)
                {
                    System.out.println("c " + c);
                     if (board[r][c] != null || board[r][c].getTeam() != board[row][column].getTeam())
                    {
                        //locations.add(new Location(r, c));
                        //count++;
                    }

                    if (board[r][c].getTeam() == board[row][column].getTeam() || board[r][c].getTeam() != board[row][column].getTeam())
                    {
                        c = -1;
                        row = 8;
                    }
                }
            }

possibly

for(int r = row; row<8; r++) {
    for(int c = column; c>-1; c--) {
        System.out.println("c "+c);
        if(board[r][c]!=null||board[r][c].getTeam()!=board[row][column].getTeam()) {
        //locations.add(new Location(r, c));
        //count++;
        }

        if(board[r][c].getTeam()==board[row][column].getTeam()||board[r][c].getTeam()!=board[row][column].getTeam()) {
            c = -1;
            row = 8;
        }
    }
}

or perhaps "row" is 1- prior to entering the outer loop?

ok fixed that

now for this r = -2 somehow and it isnt testing it and booting it out

        for (int r = row; row > -1; r--)
        {
            System.out.println(r);
            for (int c = column; c > -1; c--)
            {
                 if (board[r][c] != null || board[r][c].getTeam() != board[row][column].getTeam())
                {
                    locations.add(new Location(r, c));
                    count++;
                }

                if (board[r][c].getTeam() == board[row][column].getTeam() || board[r][c].getTeam() != board[row][column].getTeam())
                {
                    c = -1;
                    r = -1;
                }
            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.