This site requires JavaScript, please enable it in your browser!
Greenfoot back
rockon411
rockon411 wrote ...

2017/3/29

Need Help with Adding an Object

rockon411 rockon411

2017/3/29

#
I am trying to add an object from another class
public void addMinnow()
    {
        Island island = (Island) getWorld();
        island.add(new Minnow(), this.getGridX(), this.getGridY());
    }
This is the code that I am using, but I am getting a NullPointerException error regarding line 4.
Nosson1459 Nosson1459

2017/3/29

#
If you call this method when this class isn't in the world then getWorld() will return null.
rockon411 rockon411

2017/3/29

#
THANKS! I really needed that!
You need to login to post a reply.