Dear experts
Since the new version of Greenfoot 3.53 I have a simple problem. Whenever I try to access an object in the MyWorld class, I get a null pointer exception.
I don' t know why because the same thing is working with other older projects ...
Could you have a look at my code, I just made a simple interaction
This is the MyWorld class, where I generate the objects
This is another class where I want to use a reference
Thanks for your help
wueschn
import greenfoot.*; public class MyWorld extends World { private Bees b; private Frogs f; private Snakes s; public MyWorld() { super(600, 400, 1); Bees b = new Bees(); this.addObject(b, 100, 100); Frogs f = new Frogs(); this.addObject(f, 200, 200); Snakes s = new Snakes(); this.addObject(s, 300, 300); } public Bees getBees() { return this.b; } public Snakes getSnakes() { return this.s; } public Frogs getFrogs() { return this.f; } }
import greenfoot.*; public class Bees extends Actor { public void act() { if(Greenfoot.mouseClicked(this)) { //this.getWorldOfType(MyWorld.class).getFrogs().move(10); MyWorld world = (MyWorld) this.getWorld(); world.getSnakes().move(10); } } }