Hello, I have a big problem, please help me!
My world class is Game and the name of the other class is Countdown.
I used these codes:
then my Countdown class:
but if I'm compiling this, it gives me a nullpointerexception..
Stacktrace:
I don't know why..
Please help me!
Sincerely,
1 2 3 4 5 | private String countdown = "00:00" ; public String getCountdownTime() { return countdown; } |
1 2 3 4 5 6 7 8 9 10 | private Game game; public Countdown() { game = (Game) getWorld(); addPicture(); } public void addPicture() { setImage( new GreenfootImage( "Countdown: " + game.getCountdownTime(), 20 , Color.YELLOW, Color.BLACK ) ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | java.lang.NullPointerException at Countdown.addPicture(Countdown.java: 15 ) at Countdown.<init>(Countdown.java: 10 ) at Game.<init>(Game.java: 26 ) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java: 62 ) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java: 45 ) at java.lang.reflect.Constructor.newInstance(Constructor.java: 422 ) at greenfoot.core.Simulation.newInstance(Simulation.java: 607 ) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$ 4 .run(WorldHandlerDelegateIDE.java: 445 ) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java: 494 ) at greenfoot.core.Simulation.maybePause(Simulation.java: 299 ) at greenfoot.core.Simulation.runContent(Simulation.java: 212 ) at greenfoot.core.Simulation.run(Simulation.java: 205 ) |