i keep getting this error (line 38)
java.lang.NullPointerException
at defaults.act(defaults.java:38)
at greenfoot.core.Simulation.actActor(Simulation.java:567)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:530)
at greenfoot.core.Simulation.runContent(Simulation.java:193)
at greenfoot.core.Simulation.run(Simulation.java:183)
heres my code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class defaults here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class defaults extends Animal
{
public int health = 50;
private Counter counter;
public defaults()
{
}
public defaults(Counter pointCounter)
{
counter = pointCounter;
}
/**
* Act - do whatever the defaults wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(), getY() + 1);
if(canSee(bullet.class))
{
health = health - 1;
}
if (health == 0)
{
counter.add(5);
createNew();
getWorld().removeObject(this);
}
if (health == 0)
{
counter.add(5);
}
}
private void createNew()
{
defaults defaults;
defaults = new defaults();
World world;
world = getWorld();
int x = Greenfoot.getRandomNumber(600);
int y = 100;
world.addObject(defaults, x, y);
}
}
