This error comes up when a bullet hits a bomb...
Java.lang.NullPointerException
at Bullet.worldEdge(Bullet.java:33)
at Bullet.act(Bullet.java:21)
at greenfoot.core.Simulation.actActor(Simulation.java:565)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:523)
at greenfoot.core.Simulation.runContent(Simulation.java:213)
at greenfoot.core.Simulation.run(Simulation.java:203)
The code for my bullet:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Bulleyt here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bullet extends Animal
{
/**
* Act - do whatever the Bulleyt wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
canSeeC();
worldEdge();
}
public void move()
{
move(4);
}
public void worldEdge()
{
if (!(getWorld().getObjects(Bullet.class).isEmpty()))
{
if ( getX() < 20 || getX() > getWorld().getWidth() - 20)
{
getWorld().removeObject(this);
}
else if(getY() < 20 || getY() > getWorld().getHeight() - 20)
{
getWorld().removeObject(this);
}
}
}
public void canSeeC()
{
Bomb bomb = (Bomb) getOneObjectAtOffset(0, 0, Bomb.class);
if (bomb !=null)
{
getWorld().removeObject(bomb);
getWorld().removeObject(this);
}
}
}

