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

2019/1/24

java.lang.NullPointerException

TheRealAOD TheRealAOD

2019/1/24

#
Hey guys i'm new to Greenfoot and i'm recreating flappy bird for a project. I everything was fine with my code until I attempted to add a score counter into my code. Now whenever I try to run my world, it will not create it and give me the error message : java.lang.NullPointerException I should point out that the error highlighted the "public class Score extends Actor" portion of this code. I'd really appreciate the help.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)


[b]public class Score extends Actor
[/b]{
   
    public Score() {
        GreenfootImage newImage = new GreenfootImage(50, 50);
        setImage(newImage);
        
    }
    
    public void setScore(int score) {
        GreenfootImage newImage = getImage();
        newImage.clear();
        newImage.drawString("" + score, 24, 27);
        setImage(newImage);
    }
}
danpost danpost

2019/1/24

#
I do not see anything wrong with your code. Maybe you already have a Score class (??). Or, maybe there is a hidden character in your code the compiler does not like (try deleting and retyping white space around that line).
You need to login to post a reply.