I am having a problem when I am trying to target the closest enemy to the tower within a certain radius. I get a NullPointerException at lines 6 in the Arrow constructor and line 4 in the search method. The search method is referenced in the act method of the tower and it is meant to create an Arrow at the towers location when an enemy is within range. The arrow constructor is meant to turn the arrow towards the closest enemy and in the act method of the arrow I have it moving in that direction. Any help would be appreciated!
public Arrow()
{
Ground world = (Ground)getWorld();
Btower tower = world.getTower();
image();
if(tower.getNearestActor() != null) {
turnTowards(tower.getNearestActor().getX(), tower.getNearestActor().getY());
}
}public void search()
{
if(getNearestActor() != null) {
getWorld().addObject(new Arrow(), getX(), getY());
}
}
