Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.lang.OutOfMemoryError: Java heap space

807598May 1 2006 — edited May 2 2006
I'm getting this errory, java.lang.OutOfMemoryError: Java heap space, but have no idea why. I'm new to java and programming in general. I read some forum post concerning this error and did java -Xrunhprof APPNAME and looked at the results. Again..I pretty much have no idea what I'm looking at, I am curious why byte[] is at the top of the profile list and i don't have a byte array in the program.

code;First class:
import java.util.*;

public class TicTacToe
{
public static void main(String[] args)
{
TicTacToeMain mainpart = new TicTacToeMain();
mainpart.display();
}
}

class TicTacToeMain
{
char[] display = {'0','1','2','3','4','5','6','7','8'};
int[] movestaken = new int[9];
boolean gamestatus=true;

Scanner keyboard = new Scanner(System.in);
GameEngine game = new GameEngine();
public void display()
{
int i;
System.out.println("\t\t\t" + display[0] + "\t|\t" + display[1] + "\t|\t" + display[2]);
System.out.println("\t\t\t\t|\t\t|");
System.out.print("\t\t\t");
for (i=0;i <=30;i++)
{
System.out.print("_");
}
System.out.println("");
System.out.println("\t\t\t" + display[3] + "\t|\t" + display[4] + "\t|\t" + display[5]);
System.out.println("\t\t\t\t|\t\t|");
System.out.print("\t\t\t");
for (i=0;i <=30;i++)
{
System.out.print("_");
}
System.out.println("");
System.out.println("\t\t\t" + display[6] + "\t|\t" + display[7] + "\t|\t" + display[8]);
System.out.println("\t\t\t\t|\t\t|");
if (gamestatus==true)

game.engineMain();

else

getPlayersNames();
}



public void getPlayersNames()
{
int number=0;
String playerO="Computer";
String playerX="Computer";
System.out.println("Enter number of players: 1 or 2");
number = keyboard.nextInt();

if (number == 2)
{
System.out.println("Enter player X's name:");
System.out.println("Enter player O's name:");
game.twoPlayerGame();
}

if (number ==1)
{ System.out.println("Enter player O's name:");
game.onePlayerGame();
}
if (number != 1 && number !=2)
{
System.out.println("Number of Players must be 1 or 2");
getPlayersNames();
}
}

}

code;Second Class:
import java.util.*;
public class GameEngine
{
TicTacToeMain mainpart = new TicTacToeMain();
Scanner keyboard = new Scanner(System.in);
public void onePlayerGame()
{
String message="Test method oneplayer reached";
System.out.println(message);
System.exit(0);
}

public void twoPlayerGame()
{
String message="Test method twoplayer reached";
System.out.println(message);
System.exit(0);

}


public void endGame()
{
System.out.println("End game");
}
public void engineMain()
{

int move;
int location2;
int putInArray;
char[] players = {'x','o'};
System.out.println("Enter your move:");
move = keyboard.nextInt();
location2=move+1;
Arrays.fill(mainpart.display, move,location2, players[0]);
System.out.println(players[0]);
putInArray=move;
Arrays.fill(mainpart.movestaken,move,location2, putInArray);
System.out.println(mainpart.movestaken[move]);
mainpart.display();

}
}

profile section from java.hprof.txt
SITES BEGIN (ordered by live bytes) Mon May 1 17:25:10 2006
percent live alloc'ed stack class
rank self accum bytes objs bytes objs trace name
1 72.15% 72.15% 48279456 5882 48279456 5882 300465 byte[]
2 18.14% 90.30% 12140448 5882 12140448 5882 300470 char[]
3 1.20% 91.49% 799816 5881 799816 5881 301114 java.util.Scanner
4 0.84% 92.34% 564672 5882 564672 5882 300474 int[]
5 0.49% 92.83% 329392 5882 329392 5882 300473 java.util.regex.Matcher
6 0.42% 93.25% 282336 5882 282336 5882 300466 java.nio.HeapByteBuffer
7 0.42% 93.67% 282336 5882 282336 5882 300471 java.nio.HeapCharBuffer
8 0.42% 94.10% 282288 5881 282288 5881 301118 int[]
9 0.35% 94.45% 235320 5883 235320 5883 300461 sun.nio.cs.UTF_8$Decoder
10 0.35% 94.80% 235320 5883 235320 5883 300464 sun.nio.cs.StreamDecoder$CharsetSD
11 0.28% 95.08% 188192 5881 188192 5881 301116 TicTacToeMain
12 0.28% 95.36% 188192 5881 188192 5881 301117 char[]
13 0.21% 95.57% 141192 5883 141192 5883 300458 java.io.InputStreamReader
14 0.21% 95.78% 141168 5882 141168 5882 300469 java.util.Scanner$1
15 0.21% 95.99% 141168 5882 141168 5882 301081 java.lang.String
16 0.21% 96.20% 141168 5882 141168 5882 301083 java.lang.String
17 0.21% 96.42% 141168 5882 141168 5882 301087 java.lang.String
18 0.21% 96.63% 141168 5882 141168 5882 301092 java.lang.String
19 0.21% 96.84% 141168 5882 141168 5882 301096 java.lang.String
20 0.21% 97.05% 141168 5882 141168 5882 301100 java.lang.String
21 0.21% 97.26% 141168 5882 141168 5882 301101 char[]
22 0.21% 97.47% 141168 5882 141168 5882 301104 java.lang.String
23 0.21% 97.68% 141168 5882 141168 5882 301105 char[]
24 0.21% 97.89% 141168 5882 141168 5882 301108 java.lang.String
25 0.21% 98.10% 141168 5882 141168 5882 301109 char[]
26 0.14% 98.24% 94128 5883 94128 5883 300463 sun.nio.cs.Surrogate$Generator
27 0.14% 98.39% 94112 5882 94112 5882 300475 int[]
28 0.14% 98.53% 94112 5882 94112 5882 301082 char[]
29 0.14% 98.67% 94112 5882 94112 5882 301084 char[]
30 0.14% 98.81% 94112 5882 94112 5882 301088 char[]
31 0.14% 98.95% 94112 5882 94112 5882 301093 char[]
32 0.14% 99.09% 94112 5882 94112 5882 301097 char[]
33 0.14% 99.23% 94096 5881 94096 5881 301115 GameEngine
34 0.13% 99.36% 90288 1589 90288 1589 300000 char[]
35 0.06% 99.42% 38512 1587 38512 1587 300000 java.lang.String
36 0.04% 99.46% 25680 10 25680 10 300000 byte[]
37 0.02% 99.48% 12648 93 799952 5882 301062 java.text.DecimalFormat
38 0.01% 99.49% 8928 186 564672 11764 301050 char[]
39 0.01% 99.51% 8928 186 564672 11764 301068 char[]
40 0.01% 99.52% 8928 186 564672 11764 301070 char[]
41 0.01% 99.53% 8520 1 8520 1 300106 byte[]
42 0.01% 99.54% 7768 199 7768 199 300000 java.lang.Object[]
SITES END

thanks in advance,
James

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 30 2006
Added on May 1 2006
4 comments
131 views