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

2017/4/19

java.lang.OutOfMemoryError: Java heap space HELP!

1
2
Hamza_Abdulla03 Hamza_Abdulla03

2017/4/19

#
whenever i try to run my project this message comes up on the terminal window and i don't know how to solve it!
danpost danpost

2017/4/19

#
Hamza_Abdulla03 wrote...
whenever i try to run my project this message comes up on the terminal window and i don't know how to solve it!
Run a search on 'OutOfMemoryErrror Java heap space' and check out other discussions on this issue.
Yehuda Yehuda

2017/4/19

#
Hamza_Abdulla03 wrote...
whenever i try to run my project this message comes up on the terminal window and i don't know how to solve it!
danpost wrote...
Hamza_Abdulla03 wrote...
whenever i try to run my project this message comes up on the terminal window and i don't know how to solve it!
Run a search on 'OutOfMemoryErrror Java heap space' and check out other discussions on this issue.
There are a lot of other discussions on this, and it usually (from what I saw so far) turns out to be the same reason for it.
Hamza_Abdulla03 Hamza_Abdulla03

2017/4/19

#
i can't find anything that helps me i have tried most of the things
Hamza_Abdulla03 Hamza_Abdulla03

2017/4/19

#
and everything moves so slow now it keeps lagging
Hamza_Abdulla03 Hamza_Abdulla03

2017/4/19

#
not running smoothly
Yehuda Yehuda

2017/4/19

#
It would usually happen because there are too many actors in the world (more than you would think). I've seen a scenario with more than 320 different objects in the world at once, and it runs fine. So there is probably a mistake somewhere in your code.
danpost danpost

2017/4/19

#
Alright, it sounds like you have a multitude of actors in your world. Give a brief description of what your scenario is about and show the codes to your World subclass (to start with). You may also want to show the codes of any class that create an abundance of actors in the world.
Hamza_Abdulla03 Hamza_Abdulla03

2017/4/19

#
public class Background extends World
{
    GreenfootSound backgroundMusic = new GreenfootSound("Background.wav");

    private static final String bgImageName = "space1.jpg";
    private static final double scrollSpeed = 2.5;
    private static final int picWidth = (new GreenfootImage(bgImageName)).getWidth();
 
    private GreenfootImage bgImage, bgBase;
    private int scrollPosition = 0;


    public Background()
    {    
        super(5000, 400, 1);
        backgroundMusic.playLoop();
        
        setBackground(bgImageName);
        bgImage = new GreenfootImage(getBackground());
        bgBase = new GreenfootImage(picWidth, getHeight());
        bgBase.drawImage(bgImage, 0, 0);
    prepare();
}
     
     public void act()
    {
        
        scrollPosition -= scrollSpeed;
        while(scrollSpeed > 0 && scrollPosition < -picWidth) scrollPosition += picWidth;
        while(scrollSpeed < 0 && scrollPosition > 0) scrollPosition -= picWidth;
        paint(scrollPosition);

    }
     
     private void paint(int position)
    {
        GreenfootImage bg = getBackground();
        bg.drawImage(bgBase, position, 0);
        bg.drawImage(bgImage, position + picWidth, 0);
    }

    private void prepare()
    {

        Airplane airplane = new Airplane();
        addObject(airplane,75,203);
        Bomb bomb = new Bomb ();
        addObject(bomb,5000,75);
        Robot robot = new Robot();
        addObject(robot,3000,60);
        Robot robot2 = new Robot();
        addObject(robot2,846,186);
        Robot robot3 = new Robot();
        addObject(robot3,579,258);
        Robot robot4 = new Robot();
        addObject(robot4,495,87);
        Robot robot5 = new Robot();
        addObject(robot5,396,313);
        Robot robot6 = new Robot();
        addObject(robot6,352,194);
        Robot robot7 = new Robot();
        addObject(robot7,161,66);
        Bomb bomb2 = new Bomb();
        addObject(bomb2,1246,73);
        Bomb bomb3 = new Bomb();
        addObject(bomb3,1024,277);
        Bomb bomb4 = new Bomb();
        addObject(bomb4,1742,102);
        Bomb bomb5 = new Bomb();
        addObject(bomb5,1397,364);
        Bomb bomb6 = new Bomb();
        addObject(bomb6,2907,302);
        Bomb bomb7 = new Bomb();
        addObject(bomb7,2763,118);
        Bomb bomb8 = new Bomb();
        addObject(bomb8,3345,289);
        Bomb bomb9 = new Bomb();
        addObject(bomb9,3294,69);
        Bomb bomb10 = new Bomb();
        addObject(bomb10,2670,333);
        Bomb bomb11 = new Bomb();
        addObject(bomb11,161,257);
        bomb11.setLocation(621,82);
        Bomb bomb12 = new Bomb();
        addObject(bomb12,624,321);
        Ok ok = new Ok();
        addObject(ok,20,31);
        Ok ok2 = new Ok();
        addObject(ok2,26,61);
        Ok ok3 = new Ok();
        addObject(ok3,26,61);
        Ok ok4 = new Ok();
        addObject(ok4,26,61);
        Ok ok5 = new Ok();
        addObject(ok5,26,61);
        Ok ok6 = new Ok();
        addObject(ok6,26,61);
        Ok ok7 = new Ok();
        addObject(ok7,26,61);
        Ok ok8 = new Ok();
        addObject(ok8,26,61);
        Ok ok9 = new Ok();
        addObject(ok9,26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(26,61);
        ok9.setLocation(19,360);
        ok8.setLocation(20,313);
        ok7.setLocation(19,266);
        ok6.setLocation(20,219);
        ok6.setLocation(19,219);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(26,61);
        ok5.setLocation(20,174);
        ok4.setLocation(23,126);
        ok4.setLocation(21,126);
        ok3.setLocation(24,80);
        ok2.setLocation(159,16);
        ok.setLocation(21,32);
        ok3.setLocation(21,80);
        ok5.setLocation(21,171);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(159,16);
        ok2.setLocation(191,310);
        removeObject(ok2);
        ok.setLocation(17,23);
        ok3.setLocation(17,73);
        ok4.setLocation(18,122);
        ok5.setLocation(18,169);
        ok6.setLocation(18,217);
        ok7.setLocation(20,265);
        bomb11.setLocation(843,58);
        removeObject(bomb3);
        bomb5.setLocation(1431,360);
        bomb10.setLocation(2131,194);
        bomb6.setLocation(3017,290);
        bomb6.setLocation(3017,334);
        bomb8.setLocation(3502,284);
        bomb9.setLocation(3870,24);
        airplane.setLocation(132,202);
        bomb10.setLocation(2152,300);
        Robot robot8 = new Robot();
        addObject(robot8,1598,153);
        Robot robot9 = new Robot();
        addObject(robot9,1201,214);
        Robot robot10 = new Robot();
        addObject(robot10,1212,337);
        Robot robot11 = new Robot();
        addObject(robot11,1477,57);
        Robot robot12 = new Robot();
        addObject(robot12,1047,105);
        Robot robot13 = new Robot();
        addObject(robot13,2642,237);
        Robot robot14 = new Robot();
        addObject(robot14,2383,195);
        Robot robot15 = new Robot();
        addObject(robot15,2314,266);
        Robot robot16 = new Robot();
        addObject(robot16,2512,86);
        Robot robot17 = new Robot();
        addObject(robot17,2927,155);
                OKTHEN okthen = new OKTHEN();
        addObject(okthen,661,96);
        OKTHEN okthen2 = new OKTHEN();
        addObject(okthen2,834,288);
        OKTHEN okthen3 = new OKTHEN();
        addObject(okthen3,475,177);
        OKTHEN okthen4 = new OKTHEN();
        addObject(okthen4,900,279);
        OKTHEN okthen5 = new OKTHEN();
        addObject(okthen5,1031,47);
        OKTHEN okthen6 = new OKTHEN();
        addObject(okthen6,884,124);
        OKTHEN okthen7 = new OKTHEN();
        addObject(okthen7,554,183);
        OKTHEN okthen8 = new OKTHEN();
        addObject(okthen8,597,282);
        OKTHEN okthen9 = new OKTHEN();
        addObject(okthen9,422,326);
        OKTHEN okthen10 = new OKTHEN();
        addObject(okthen10,369,307);
        OKTHEN okthen11 = new OKTHEN();
        addObject(okthen11,268,196);
        OKTHEN okthen12 = new OKTHEN();
        addObject(okthen12,252,112);
        OKTHEN okthen13 = new OKTHEN();
        addObject(okthen13,390,72);
        OKTHEN okthen14 = new OKTHEN();
        addObject(okthen14,733,237);
        OKTHEN okthen15 = new OKTHEN();
        addObject(okthen15,1045,312);
        OKTHEN okthen16 = new OKTHEN();
        addObject(okthen16,986,226);
        OKTHEN okthen17 = new OKTHEN();
        addObject(okthen17,1070,177);
        OKTHEN okthen18 = new OKTHEN();
        addObject(okthen18,1009,136);
        OKTHEN okthen19 = new OKTHEN();
        addObject(okthen19,921,105);
        OKTHEN okthen20 = new OKTHEN();
        addObject(okthen20,784,60);
        OKTHEN okthen21 = new OKTHEN();
        addObject(okthen21,743,58);
        OKTHEN okthen22 = new OKTHEN();
        addObject(okthen22,594,29);
        OKTHEN okthen23 = new OKTHEN();
        addObject(okthen23,503,9);
        OKTHEN okthen24 = new OKTHEN();
        addObject(okthen24,449,56);
        OKTHEN okthen25 = new OKTHEN();
        addObject(okthen25,401,156);

    }
}
Hamza_Abdulla03 Hamza_Abdulla03

2017/4/19

#
that is my background
Yehuda Yehuda

2017/4/19

#
Do the Airplane, Bomb, Robot, Ok, or OKTHEN classes add objects into the world in their code. (Your code is quite annoying since lines 65 - 66, 88 - 89, 104 - 178 are unnecessary.)
danpost danpost

2017/4/19

#
The width of your world is a bit extreme, most screens are only around 1000 pixels wide. You can use code to regulate the size of the scrolling area. I do not think I have ever created a scenario with a window width of much more than 800 or so.
Yehuda Yehuda

2017/4/19

#
danpost wrote...
The width of your world is a bit extreme, most screens are only around 1000 pixels wide. You can use code to regulate the size of the scrolling area. I do not think I have ever created a scenario with a window width of much more than 800 or so.
I overlooked that.
Hamza_Abdulla03 Hamza_Abdulla03

2017/4/19

#
changed it to 800 but still like that
Yehuda Yehuda

2017/4/19

#
Yehuda wrote...
Do the Airplane, Bomb, Robot, Ok, or OKTHEN classes add objects into the world in their code.
I wouldn't think that having 62 objects in a world at once should make that error.
(Your code is quite annoying since lines 65 - 66, 88 - 89, 104 - 178 are unnecessary.)
Instead of adding objects at one location then switching it, just place the objects in the place that you want them to be. There are two objects that you add and remove before anything else can happen.
There are more replies on the next page.
1
2