It still says NullPointerException.
This is what I have in the Bullet class: In the Head class:And in the balloon class: This is everything relevant to my query.
private int imageIndex;
public void pop()
{
Balloon balloon = (Balloon)getOneIntersectingObject(Balloon.class);
int balloonColour = balloon.getColourInt();
int headColour = getHeadColourInt();
if (balloon!=null)
{
if(balloonColour == headColour)
{
getWorld().removeObject(this);
getWorld().removeObject(balloon);
}
else
{
getWorld().removeObject(this);
}
}
}
public void setHeadColour(int index)
{
imageIndex = index;
}
public int getHeadColourInt()
{
return imageIndex;
} private GreenfootImage[]images={new GreenfootImage("button-red.png"), new GreenfootImage("button-blue.png"), new GreenfootImage("button-yellow.png")};
private int imageIndex;
public Head()
{
setColour(0);
}
public int getColourInt()
{
return imageIndex;
}
public void setColour(int index)
{
imageIndex = index;
setImage(images[index]);
Bullet bullet = new Bullet();
bullet.setHeadColour(index);
}
public void act()
{
headChange();
}
public void headChange()
{
if (Greenfoot.isKeyDown("z"))
{
setColour(0);
}
if (Greenfoot.isKeyDown("x"))
{
setColour(1);
}
if (Greenfoot.isKeyDown("c"))
{
setColour(2);
}
}private GreenfootImage[]images={new GreenfootImage("balloon1.png"), new GreenfootImage("balloon2.png"), new GreenfootImage("balloon3.png")};
private int imageIndex;
public int getColourInt()
{
return imageIndex;
}
public void setColour(int index)
{
imageIndex = index;
setImage(images[index]);
}
public Balloon()
{
setColour(Greenfoot.getRandomNumber(images.length));
}

