Results 1 to 5 of 5
- 11-03-2009, 07:11 AM #1
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
Java.lang.ExceptionOutOfMemory: Java heap space. lulzwut?!
Hi!
Im trying to make like moving objects and stuff..
So I got this simple picture movig around on the screen.
But the problem is i get the error shown in topic after running it for a while.
I'v read about this error and that it would occure since things are piling up due to lack of threading.
So I tried to thread it but im not good at it so I cant see where Im suppose to thread and how...
I would really appriciate help on this ty =)
Heres my code if needed:
PHP Code:/** * You must use Threading! */ import javax.swing.*; import javax.imageio.*; import java.awt.*; import java.io.*; import java.awt.image.*; import java.awt.image.BufferedImage; import java.util.*; public class TestingArea { static Vector <Image> list = new Vector<Image>(); static int X = 0; static int Y = 0; public static void main(String[] args) { // TODO, add your application code gameFrame gf = new gameFrame(); while (true){ X += 10; Y += 2; if (X>400){ X = 0; Y = 0; } paintIt obj = new paintIt(); new Thread(obj).start(); gf.add(obj); Graphics g; gf.repaint(); try{ //do what you want to do before sleeping Thread.currentThread().sleep(100);//sleep for 1000 ms //do what you want to do after sleeptig } catch(Exception ie){ //If this thread was intrrupted by nother thread } } } } class gameFrame extends JFrame{ public gameFrame(){ paintIt p = new paintIt(); add(p); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(600,400); setTitle("Image test"); setVisible(true); } } class paintIt extends JPanel implements Runnable{ BufferedImage pic; public void paintComponent(Graphics g){ super.paintComponent(g); try{ BufferedImage pic = ImageIO.read(new File("C:\\Users\\Andreas\\Bilder\\CNDF.png")); TestingArea.list.add(pic); g.drawImage(pic,TestingArea.X,TestingArea.Y,null); }catch (Exception e){ e.printStackTrace(); } } public void run(){ } }
- 11-03-2009, 07:14 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 11-03-2009, 07:40 AM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
Okej now I'v read that.
But I still dont get it..
Whats wrong with my code that makes something pile up uppon eachother?
I meen, I use a thread got the paint method and all..
I cant find what is causeing it..
- 11-03-2009, 07:46 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
You keep on adding paintIt objects to your gameFrame object without limit. btw, lots of your code doesn't make any sense and forget about Threads for now, you don't need them.
kind regards,
Jos
- 11-03-2009, 04:01 PM #5
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
Similar Threads
-
java.lang.OutOfMemoryError: Java heap space
By paul in forum Advanced JavaReplies: 11Last Post: 06-12-2010, 05:30 PM -
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
By vasavi.singh in forum Advanced JavaReplies: 10Last Post: 05-11-2009, 11:56 AM -
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 -
java.lang.OutOfMemoryError: Java heap space
By vidjogamer in forum New To JavaReplies: 3Last Post: 02-06-2009, 06:52 AM -
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