Hi everyone,
I have a question: I have the following class:
and it throws this exception:
I don't know what's wrong.
The error must be in this Part of the code:
because when I replace it with a number like 800 everything works
import greenfoot.*; public class Ground extends Actor { private int y = this.getWorld().getHeight() - this.getImage().getHeight() / 2; }
java.lang.NullPointerException at Ground.<init>(Ground.java:4) at MyWorld.<init>(MyWorld.java:11) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at greenfoot.core.Simulation.newInstance(Simulation.java:580) at greenfoot.platforms.ide.WorldHandlerDelegateIDE.lambda$instantiateNewWorld$0(WorldHandlerDelegateIDE.java:143) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:470) at greenfoot.core.Simulation.maybePause(Simulation.java:299) at greenfoot.core.Simulation.runContent(Simulation.java:190) at greenfoot.core.Simulation.run(Simulation.java:183)
this.getWorld().getHeight()