0

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!

2
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by slayer10
0

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.

0

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;
                    }
                }
            }

Edited by Dani: Formatting fixed

0

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?

0

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;
                }
            }
        }

Edited by Dani: Formatting fixed

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.