Java Heap Space Error

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2007
Posts: 26
Reputation: slayer10 is an unknown quantity at this point 
Solved Threads: 0
slayer10 slayer10 is offline Offline
Light Poster

Java Heap Space Error

 
0
  #1
Feb 28th, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,484
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 517
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Java Heap Space Error

 
0
  #2
Feb 28th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 26
Reputation: slayer10 is an unknown quantity at this point 
Solved Threads: 0
slayer10 slayer10 is offline Offline
Light Poster

Re: Java Heap Space Error

 
0
  #3
Feb 28th, 2008
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;
}
}
}
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,484
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 517
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Java Heap Space Error

 
0
  #4
Feb 28th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 26
Reputation: slayer10 is an unknown quantity at this point 
Solved Threads: 0
slayer10 slayer10 is offline Offline
Light Poster

Re: Java Heap Space Error

 
0
  #5
Feb 28th, 2008
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;
}
}
}
Last edited by slayer10; Feb 28th, 2008 at 8:32 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC