• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway


Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am creating a java program that is like a card base ball game.
when i run 95 percent of the program it works like crazy. but when i try to allow the user to start a new game versus a player or versus the computer i get an error. i have the jpanel calling a new JFrame through a action listener and then i get the error as follows "Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space".

The way that i have it is that i have a class DrawBoard extends JFrame that calls a Board extends JPanel that handles all of the painting that resembles a base ball game. I also have a JMenuBar, JMenu, and JMenuItems that allows the user to have a rematch against the current team, (that works), or to have a new game with a choice between the computer or a actual player. Now when they choose this option its supposed to open up my NewGame application Awt which would allow them to type in the information using 1 jtextfield, and two JComboBoxs. the problem is that when i call the new game application i get the error and i dont see how i can possibly have a memory leak. could it be bc i have the newgame class as a private class inside of the Board extends JPanel?
I cant possibly copy my code into here bc its more than 2 thousand lines of code.
would appreciate ne useful information.
author and iconoclast
Posts: 24203
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephen,

Welcome to JavaRanch!

Well, there are two possibilities:

1) You're just a little bit out of memory; or

2) You're a lot out of memory.

When you start your program, you can use a larger Java heap; this might solve the problem. Try

java -Xmx128m YourClassName

to run with double the default heap size. If this works, then it was problem number one; this isn't uncommon.

If it still fails, then it's most likely option 2, and there's a problem with your code. It could be something as simple as this (a common mistake

Every time you create a Something, it will create a new Something, which will create a new Something... until all memory is filled, or you get a stack overflow, whichever comes first. Sometimes it's a little more subtle: class A contains a new instance of class B, which contains an instance of class A, which contains B, etc, etc. Finally, it could be a loop which is creating objects and adding them to a Collection, or appending Strings to a StringBuffer; the loop could have an error in it which causes it to never terminate until all memory fills up.
stephen shields
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for that folks
i found the error
in my infinite stupidity i forgot to increment a counter in a while loop to add team names to the combo box.

string line = mystring.readLine();
count = 0;
teams[count]= line;
I found it by the usual debugging println's
after that i took the string out and just added the items as each line was read

thank you for you time tho
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!