Hey I'm having some issues with this bit of code in my world constructor.
My code looks like this:
and yet when it compiles it says "The world constructor threw an exception."
this is the exception:
whats going on? I'm very new to java and greenfoot
public class MyWorld extends World
{
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 100, 1, false);
//prompts the user for how far away to place a Treasure object.
String str = Greenfoot.ask("how far away, in cm is the treasure?");
int tDist = Integer.parseInt(str.trim())+5;
addObject(new Treasure(), getWidth()/2 + tDist, 50);
//creates a starting line and a robot
addObject(new Start(), getWidth()/2, 50);
addObject(new Robot(), getWidth()/2, 50);
}java.lang.NullPointerException at MyWorld.<init>(MyWorld.java:22) 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)


