Hello, please help! My code compiles without any syntax errors, however, when I attempt to run it I keep getting the following error message:
java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016)
at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:186)
at greenfoot.util.GraphicsUtilities.createCompatibleTranslucentImage(GraphicsUtilities.java:189)
at greenfoot.GreenfootImage.<init>(GreenfootImage.java:130)
at Bubble.<init>(Bubble.java:28)
at Bubble.<init>(Bubble.java:50)
at Bubble.<init>(Bubble.java:20)
at Space.setUp(Space.java:33)
at Space.<init>(Space.java:20)
public class Bubble extends Actor
{
private int speed;
/**
* Create a Bubble that floats, with random size and random color.
*/
public Bubble()
{
// create a random size, between 10 and 110 pixels
this(Greenfoot.getRandomNumber(01), + 10);
}
/**
* Create a Bubble that floats, with a given size and random color.
*/
public Bubble(int size)
{
GreenfootImage img = new GreenfootImage(size, size);
// create a random color, with every color channel between 30 and 230
int red = Greenfoot.getRandomNumber(200) + 30;
int green = Greenfoot.getRandomNumber(200) + 30;
int blue = Greenfoot.getRandomNumber(200) + 30;
int alpha = Greenfoot.getRandomNumber(190) + 60;
img.setColor(new Color(red, green, blue, alpha));
img.fillOval(0, 0, size-1, size-1);
setImage(img);
//random speed: 1 to 4
speed = Greenfoot.getRandomNumber(4) + 1;
}
int x = 0;
/**
* Create a Bubble that floats, with given size and initial float direction.
*/
public Bubble(int size, int direction)
{
this(size);
setRotation(direction);
setLocation (getX() *63, getY());
}
/**
* Float.
*/
public void act()
{
//addObject (new Bubble() );
Actor body = getOneIntersectingObject(Bubble.class);
if (isAtEdge()) {
turn(180);
}
move(speed);
setLocation(getX()-4, getY());
if (Greenfoot.getRandomNumber(100) < 50) {
turn(Greenfoot.getRandomNumber(5) -2 ); // -2 to 2
}
}
}
public class Space extends World
{
/**
* Create Space. Make it black.
*/
public Space()
{
super(900, 600, 1);
getBackground().setColor(Color.BLACK);
getBackground().fill();
setUp();
}
/**
* Create 21 random bubbbles. Create 10 bubbles in horizontal line.
*/
private void setUp()
{
Bubble[] bubble = new Bubble[21];
int i = 0;
while (i < 21 )
{
addObject(new Bubble(), Greenfoot.getRandomNumber(900), Greenfoot.getRandomNumber(600) );
addObject(new Bubble(),getWidth() / 2, getHeight() / 2);
bubble[i] = new Bubble();
addObject(new Bubble(10+i), i*45, 30);
i = i + 1;
}
int x = 0;
while ( x < 10 )
{
addObject(new Bubble (x * 10 + 10), 300 + x*40, 100);
x = x +1;
}
}
}
