Well the title says it. here is the terminal window when the enemy touches the player:
java.lang.NullPointerException
at Enemy.hit(Enemy.java:37)
at Enemy.act(Enemy.java:21)
at greenfoot.core.Simulation.actActor(Simulation.java:568)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.NullPointerException
at Enemy.hit(Enemy.java:37)
at Enemy.act(Enemy.java:21)
at greenfoot.core.Simulation.actActor(Simulation.java:568)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.NullPointerException
at Enemy.hit(Enemy.java:37)
at Enemy.act(Enemy.java:21)
at greenfoot.core.Simulation.actActor(Simulation.java:568)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.NullPointerException
at Enemy.hit(Enemy.java:37)
at Enemy.act(Enemy.java:21)
at greenfoot.core.Simulation.actActor(Simulation.java:568)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.NullPointerException
at Enemy.hit(Enemy.java:37)
at Enemy.act(Enemy.java:21)
at greenfoot.core.Simulation.actActor(Simulation.java:568)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
and here is the project code of the enemy:
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 { private Health aHealth; /** * 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() { // Add your action code here. followPlayer(); hit(); } public void followPlayer() { Player pl = (Player) getWorld().getObjects(Player.class).get(0); turnTowards(pl.getX(), pl.getY()); move(4); } public void hit() { Actor Enemy; Enemy = getOneIntersectingObject(Player.class); if (Enemy != null) { aHealth.sub(150); getWorld().removeObjects(getWorld().getObjects(Enemy.class)); } } }