I have an Actor called Car.
Currently I am adding a Car object via this call: addObject(new Car(), xPos, yPos);
However, I am wanting to reference this Car in some code, so I have modified this to have this code at the top: private Car aCar; and am trying to add this Car object via this code: addObject(aCar, xPos, yPos);
When I try and compile this, I get the following terminal data:
java.lang.NullPointerException
at greenfoot.World.addObject(World.java:392)
at CarWorld.CreateCar(CarWorld.java:34)
at CarWorld.<init>(CarWorld.java:29)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at greenfoot.core.Simulation.newInstance(Simulation.java:520)
at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:406)
at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:411)
at greenfoot.core.Simulation.maybePause(Simulation.java:269)
at greenfoot.core.Simulation.runContent(Simulation.java:201)
at greenfoot.core.Simulation.run(Simulation.java:194)
What am I doing wrong?
thanks