Results 1 to 3 of 3
- 05-24-2011, 06:23 AM #1
Member
- Join Date
- May 2011
- Posts
- 1
- Rep Power
- 0
PLease help. The error is: exception in thread "main" java.lang.OutOfMemoryError:Java
heap space.
My codes:
Java Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; public class board implements ActionListener{ JButton y[]=new JButton[1000000]; int xa, ya, i, l; JFrame Dave; public static void main(String[] args){ board chuy = new board(); chuy.setFrame(); } public void setFrame(){ xa=0; ya=0; l=0; i=1; Dave = new JFrame("Board"); Dave.setLayout(new GraphPaperLayout(new Dimension(1000,1000))); while(l<9999){ y[i]=new JButton(""); Dave.add(y[i], new Rectangle(xa,ya,1,1)); if(xa<=1000){ if(xa==1000){ xa=0; ya++; } else xa++; } } i++; Dave.setVisible(true); Dave.setSize(360,400); Dave.setLocation(100,100); Dave.setResizable(false); Dave.setDefaultCloseOperation(Dave.DISPOSE_ON_CLOSE); } public void actionPerformed(ActionEvent e){ } }Last edited by Fubarable; 05-24-2011 at 06:26 AM. Reason: code tags added
-
Have you tried giving your program more available heap memory on the command line (or via your IDE if using one)?
- 05-24-2011, 07:18 AM #3
A comment on coding style: your button array would be more representative if declared as a two-dimensional array, and the while(...) loop would be more expressive coded as nested for(...) loops.
Better still would be to declare a static final variable SIDE (or WIDTH and HEIGHT if these are not always to be equal) and use the variable/s in the layout parameters, button array declaration and loop limits. Then if you want to change from 1000 X 1000 to some other numbers, that change is in only one place.Java Code:JButton[][] buttons = new JButton[1000][1000]; : : for (int x = 0; x < 1000; x++) { for (int y = 0; y < 1000; y++) { buttons[x][y] = new JButton(); dave.add(buttons[x][y], new Rectangle(x, y, 1, 1)); } }
db
Similar Threads
-
Question about error "Exception in thread "main" java.lang.NoSuchMethodError: main
By ferdzz in forum New To JavaReplies: 5Last Post: 06-22-2010, 03:51 PM -
Error - Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap
By ganchinyong in forum AWT / SwingReplies: 4Last Post: 06-03-2010, 08:40 AM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
By Ms.Ranjan in forum New To JavaReplies: 3Last Post: 04-22-2009, 08:25 PM -
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
By Eku in forum NetBeansReplies: 14Last Post: 06-12-2008, 08:36 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks