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

2020/3/11

Level selection returns null pointer exception

hahaMoth hahaMoth

2020/3/11

#
hi im making a code where i click an actor which serves as the "play button" which calls the a method in the world which gets the value of the knight. i initiated a variable called levelType which is an integer type (0 or 1) which separates 2 worlds which are the tutorial and the actual game. everytime i press the play button, i get a null pointer exception error but the worlds still load. what do i do to solve this? Play Button Class
public class PlayButton extends Actor
{
    public PlayButton()
    {
        setImage("SlayButton.png");
    }

    public void act() 
    {

        MainMenu mainMenu = (MainMenu) getWorld();
        Knight knight = mainMenu.getKnight();
        if(Greenfoot.mouseClicked(this))
        {
            Greenfoot.setWorld(new Level0());
            knight.actualLevel();
        }

    }

}
World Class
public class Forest1 extends World
{
    public Forest1()
    {
        this(new Knight());
    }

    public Forest1(Knight knight)
    {    
        super(600, 400, 1);
        Instructions instructions = new Instructions("instructions1.png");
        setBackground("forest.jpg");
        addObject(new Ground("ground.png"), 300, 388);
        addObject(knight, 60, 333);
        addObject(instructions,295,70);
        setPaintOrder(Knight.class);
    }
}
danpost danpost

2020/3/11

#
hahaMoth wrote...
everytime i press the play button, i get a null pointer exception error but the worlds still load. what do i do to solve this?
Need to show MainMenu class codes.
You need to login to post a reply.