This site requires JavaScript, please enable it in your browser!
Greenfoot back
saybrgg
saybrgg wrote ...

2024/4/14

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

saybrgg saybrgg

2024/4/14

#
import greenfoot.*;
import java.awt.Color;
import java.util.List;
import java.util.ArrayList;

public class levelBackground extends World
{
    platformMap map = new platformMap();
    GreenfootImage mapImg = map.getImage();
    final int MAPIMGWIDTH = mapImg.getWidth();
    final int MAPIMGHEIGHT = mapImg.getHeight();
    Block platformTemplate = new Block(0,0);
    GreenfootImage pfImg = platformTemplate.getImage();
    final int PLATFORMHEIGHT = pfImg.getHeight();
    final int PLATFORMWIDTH = pfImg.getWidth();
    final int MAPWIDTH = MAPIMGWIDTH * PLATFORMWIDTH;
    final int MAPHEIGHT = MAPIMGHEIGHT * PLATFORMHEIGHT;
    private List<Block> thePlatforms = new ArrayList<Block>();
    int leftBound = 0;
    int bottomBound = MAPHEIGHT;
    int topBound = MAPHEIGHT - getHeight();
    int rightBound = getWidth();

    public levelBackground()
    {    
        super(1000, 600, 1); 
        makeMap();
        update();
    }

    public void makeMap()
    {
        for(int y=0; y<MAPIMGHEIGHT; y++)
        {
            for(int x=0; x<MAPIMGWIDTH; x++)
            {
                int colorRGB = mapImg.getColorAt(x, y).getRGB();
                if(colorRGB==Color.BLACK.getRGB())
                {
                    int mapX = x * PLATFORMWIDTH + PLATFORMWIDTH/2;
                    int mapY = y * PLATFORMHEIGHT + PLATFORMHEIGHT/2;
                    thePlatforms.add(new Block(mapX,mapY));
                }
            }
        }
    }

    public void update()
    {
        Block thisPlatform;
        int thisPlatformX;
        int thisPlatformY;
        int screenX;
        int screenY;
        for(int i=0; i<thePlatforms.size(); i++)
        {
            thisPlatform = thePlatforms.get(i);
            thisPlatformX = thisPlatform.mapX;
            thisPlatformY = thisPlatform.mapY;

            if(thisPlatformX>=leftBound && thisPlatformX<=rightBound && thisPlatformY>=topBound && thisPlatformY<=bottomBound)
            {
                screenX = thisPlatformX - leftBound;
                screenY = thisPlatformY - topBound;
                if(thisPlatform.getWorld()==null)
                {
                    addObject(thisPlatform, screenX, screenY);
                }
            }
        }
    }
}
danpost danpost

2024/4/15

#
saybrgg wrote...
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space << Code Omitted >>
How big is the map image?
saybrgg saybrgg

2024/4/30

#
From this code all I get is this: java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75) at java.awt.image.Raster.createPackedRaster(Raster.java:467) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:186) at greenfoot.util.GraphicsUtilities.createCompatibleTranslucentImage(GraphicsUtilities.java:189) at greenfoot.GreenfootImage.scale(GreenfootImage.java:388) at Block.<init>(Block.java:16) at levelBackground.makeMap(levelBackground.java:47) at levelBackground.<init>(levelBackground.java:32) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at greenfoot.core.Simulation.newInstance(Simulation.java:607) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$4.run(WorldHandlerDelegateIDE.java:441) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:494) at greenfoot.core.Simulation.maybePause(Simulation.java:299) at greenfoot.core.Simulation.runContent(Simulation.java:212) at greenfoot.core.Simulation.run(Simulation.java:205) Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75) at java.awt.image.Raster.createPackedRaster(Raster.java:467) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) at java.awt.image.BufferedImage.<init>(BufferedImage.java:340) at com.sun.java.swing.plaf.windows.XPStyle$SkinPainter.createImage(XPStyle.java:673) at sun.swing.CachedPainter.paint0(CachedPainter.java:139) at sun.swing.CachedPainter.paint(CachedPainter.java:111) at com.sun.java.swing.plaf.windows.XPStyle$Skin.paintSkinRaw(XPStyle.java:610) at com.sun.java.swing.plaf.windows.AnimationController.paintSkin(AnimationController.java:253) at com.sun.java.swing.plaf.windows.XPStyle$Skin.paintSkin(XPStyle.java:589) at com.sun.java.swing.plaf.windows.WindowsButtonUI.paintXPButtonBackground(WindowsButtonUI.java:280) at com.sun.java.swing.plaf.windows.WindowsButtonUI.paint(WindowsButtonUI.java:165) at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161) at javax.swing.JComponent.paintComponent(JComponent.java:778) at javax.swing.JComponent.paint(JComponent.java:1054) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JLayeredPane.paint(JLayeredPane.java:586) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paintToOffscreen(JComponent.java:5229) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1572) at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1495) at javax.swing.RepaintManager.paint(RepaintManager.java:1265) at javax.swing.JComponent.paint(JComponent.java:1040) at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39) at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:79) at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:116) at java.awt.Container.paint(Container.java:1973) Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75) at java.awt.image.Raster.createPackedRaster(Raster.java:467) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) at java.awt.image.BufferedImage.<init>(BufferedImage.java:340) at com.sun.java.swing.plaf.windows.XPStyle$SkinPainter.createImage(XPStyle.java:673) at sun.swing.CachedPainter.paint0(CachedPainter.java:139) at sun.swing.CachedPainter.paint(CachedPainter.java:111) at com.sun.java.swing.plaf.windows.XPStyle$Skin.paintSkinRaw(XPStyle.java:610) at com.sun.java.swing.plaf.windows.XPStyle$Skin.paintSkin(XPStyle.java:592) at com.sun.java.swing.plaf.windows.XPStyle$XPImageBorder.paintBorder(XPStyle.java:372) at javax.swing.border.TitledBorder.paintBorder(TitledBorder.java:329) at javax.swing.JComponent.paintBorder(JComponent.java:947) at javax.swing.JComponent.paint(JComponent.java:1055) at javax.swing.JComponent.paintToOffscreen(JComponent.java:5222) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1572) at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1495) at javax.swing.RepaintManager.paint(RepaintManager.java:1265) at javax.swing.JComponent._paintImmediately(JComponent.java:5170) at javax.swing.JComponent.paintImmediately(JComponent.java:4981) at javax.swing.RepaintManager$4.run(RepaintManager.java:824) at javax.swing.RepaintManager$4.run(RepaintManager.java:807) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:807) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:782) at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:731) at javax.swing.RepaintManager.access$1300(RepaintManager.java:64) at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1720) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:702) Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75) at java.awt.image.Raster.createPackedRaster(Raster.java:467) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) at java.awt.image.BufferedImage.<init>(BufferedImage.java:340) at com.sun.java.swing.plaf.windows.XPStyle$SkinPainter.createImage(XPStyle.java:673) at sun.swing.CachedPainter.paint0(CachedPainter.java:139) at sun.swing.CachedPainter.paint(CachedPainter.java:111) at com.sun.java.swing.plaf.windows.XPStyle$Skin.paintSkinRaw(XPStyle.java:610) at com.sun.java.swing.plaf.windows.XPStyle$Skin.paintSkin(XPStyle.java:592) at com.sun.java.swing.plaf.windows.XPStyle$XPImageBorder.paintBorder(XPStyle.java:372) at javax.swing.border.TitledBorder.paintBorder(TitledBorder.java:329) at javax.swing.JComponent.paintBorder(JComponent.java:947) at javax.swing.JComponent.paint(JComponent.java:1055) at javax.swing.JComponent.paintToOffscreen(JComponent.java:5222) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1572) at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1495) at javax.swing.RepaintManager.paint(RepaintManager.java:1265) at javax.swing.JComponent._paintImmediately(JComponent.java:5170) at javax.swing.JComponent.paintImmediately(JComponent.java:4981) at javax.swing.RepaintManager$4.run(RepaintManager.java:824) at javax.swing.RepaintManager$4.run(RepaintManager.java:807) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:807) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:782) at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:731) at javax.swing.RepaintManager.access$1300(RepaintManager.java:64) at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1720) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:702) Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
danpost danpost

2024/5/2

#
saybrgg wrote...
From this code all I get is this: << Error Trace Omitted >>
The error is coming from something in your Block class. Please show its codes.
You need to login to post a reply.