This site requires JavaScript, please enable it in your browser!
Greenfoot back
Jasonertia
Jasonertia wrote ...

2015/11/17

Null Pointer Exception

Jasonertia Jasonertia

2015/11/17

#
public void act()
    {
        checkDeath();
        generateStars(-1);
        generateTargets();
        addBuilding();
        bkgMusic.playLoop();
        generateAliens();
        checkPop();
    }
public void checkDeath(){ 
        List buildings = getObjects(Building.class);
        if(buildings.isEmpty()){
            endGame();
        }
    }
    public void endGame(){
        Counter population = ((Counter) getObjects(Counter.class).get(1)); 
        if( population.getValue() < 100 )
        {
            EndWorld3 end3 = new EndWorld3(d.getValue());
            Greenfoot.setWorld(end3);
            bkgMusic.stop();
        }
    }
public EndWorld3(int score)
    {    
        super(400, 400, 1); 
        Counter d = new Counter("Population: ");
        d.setValue(score);
        addObject(d, 100, 100);
    }
Hello! I'd appreciate some help with this code. When I run the game and the game is over, I get a null pointer exception at Space.endGame(Space.java:92) at Space.checkDeath(Space.java:71) at Space.act(Space.java:31) Thank you for your time!
davmac davmac

2015/11/17

#
Is the first piece of code you posted the code for the "Space" class? According to the stack trace, the exception occurs on line 92. Which line is line 92?
You need to login to post a reply.