the error states
java.lang.NullPointerException
at enemySpawner.act(enemySpawner.java:29)
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)
yet line 29 isnt supposted to run till later, whats up ?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class enemySpawner here. * * @author (your name) * @version (a version number or a date) */ public class enemySpawner extends Actor { boolean enemys= false; int def_Val = 0; int counter = def_Val; boolean runonce = false; int x = 0; boolean level2check = false; /** * Act - do whatever the enemySpawner wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(getWorld().getObjects(Player.class).get(0).currentlv == 2){ level2check = true; mainCode(); } if(getWorld().getObjects(Player.class).get(0).currentlv == 5 &&level2check == true){ level_5(); } } void mainCode() { if(enemys == true){ getWorld().addObject(new enemy(), getX(), getY()); getWorld().showText(""+getWorld().getObjects(enemy.class).get(0).num, getX(), getY()); if(getWorld().getObjects(enemy.class).get(0).num >= 4) { getWorld().removeObject(this); } } } void level_5(){ getWorld().addObject(new enemy(), getX(), getY()); getWorld().showText(""+getWorld().getObjects(enemy.class).get(0).num, getX(), getY()); if(getWorld().getObjects(enemy.class).get(0).num >= 8) { getWorld().removeObject(this); } } }