Hello, so my game is crashing when Enemy gets destroyed. The crash error i get is And here is the Enemy code:Any ideas how to fix it ? :o I was trying to make this Enemy follow actor "Hero" which is controlled by the user.
java.lang.NullPointerException at Enemy.act(Enemy.java:22) at greenfoot.core.Simulation.actActor(Simulation.java:594) at greenfoot.core.Simulation.runOneLoop(Simulation.java:552) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Enemy here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Enemy extends Actor
{
/**
* Act - do whatever the Enemy wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
destroyEnemies();
Hero hero = (Hero)getWorld().getObjects(Hero.class).get(0);
turnTowards(hero.getX(), hero.getY());
}
public void destroyEnemies()
{
//"Enemy" can be any class that you want the bullet to destroy.
Actor Bullet = getOneObjectAtOffset(0, 0, Bullet.class);
if (Bullet != null){
getWorld().removeObject(Bullet);
getWorld().removeObject(this);
}
}
}

