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

2017/3/30

Help!!! java.lang.OutOfMemoryError: Java heap space

AustinProkopishin AustinProkopishin

2017/3/30

#
I keep getting this error message when I try to place 10 actors randomly around the world. I need help fixing this! I can post code if needed.
danpost danpost

2017/3/30

#
AustinProkopishin wrote...
I keep getting this error message when I try to place 10 actors randomly around the world. I need help fixing this! I can post code if needed.
Of course, it is needed. Also the exact error message output.
AustinProkopishin AustinProkopishin

2017/3/30

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * The game world.
 * 
 * @author Austin Prokopishin 
 * @version 1.0
 */
public class MyWorld extends World
{
     GreenfootSound backgroundMusic = new GreenfootSound("8-Bit Dubstep IV.mp3");
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MyWorld()
    {    
        // Create a new world with 1600x770 cells with a cell size of 1x1 pixels.
        super(1600, 770, 1); 
        populate();
        backgroundMusic.playLoop();
    }
    public void populate(){
       int x;
       int y;
       for(int i = 0; 1 < 5; i++) {
      x = (int)(Math.random() * 1600);
      y = (int)(Math.random() * 770);
      addObject(new Asteroid1(), x, y);
      addObject(new Asteroid2(), x, y);
    } 
  }
    
}
this is the whole class but the area where I am having trouble is in the populate method
danpost danpost

2017/3/30

#
AustinProkopishin wrote...
< Code Omitted > this is the whole class but the area where I am having trouble is in the populate method
Okay, the only places that are in question now is your Asteroid1 and Asteroid2 classes.
AustinProkopishin AustinProkopishin

2017/3/30

#
the asteroid 1 and 2 classes are identical except for different photos for their classes, here is the code:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * The asteroids.
 * 
 * @author Austin Prokopishin
 * @version 1.0
 */
public class Asteroid1 extends Actor
{
    /**
     * Act - do whatever the Asteroid1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
   GifImage gifImage = new GifImage("explosion.gif");
    public void act() 
    {
       
          // from modern-crab
       if (isTouching(LazerBolt.class)) {
           getWorld().addObject (new explosion(), getX(), getY());
           removeTouching(LazerBolt.class);
           getWorld().removeObject(this);
           
    
    }    

}
}
danpost danpost

2017/3/30

#
Ah, I found the problem. Not easy to spot. Look closely at line 26 in your MyWorld class (the 'for' structure).
AustinProkopishin AustinProkopishin

2017/3/30

#
Oh my gosh! *facepalm* I cannot believe it was that simple!!! thank you so much for your help and speedy replies!!
You need to login to post a reply.