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

2012/5/17

A strange NullPointer

darkmist255 darkmist255

2012/5/17

#
I thought my days of problems with the old "getWorld().removeObject(this)" were over, but they seem to have come back in a strange way. The code itself is very simple and I use it all the time without problem:
public void checkRemove()
    {
        if(remove)
        {
            getWorld().removeObject(this);
        }
    }
This method is called as the LAST call from the act() method by any given object. My question here is why is "this" a null pointer? I've already tested and determined that "getWorld()" is not a null pointer.
davmac davmac

2012/5/17

#
'this' cannot be a null pointer. So, I'm guessing you're incorrect about 'getWorld()' not returning null. Note that it returns null only if the actor has already been removed from the world, so I'm guessing that's what has happened in the case when you get an exception.
darkmist255 darkmist255

2012/5/17

#
Hmm, I'll have to look into it further, it's always a possibility.
darkmist255 darkmist255

2012/5/17

#
Well, all appears to be fine and dandy after cleaning up a bunch of code, I think I must've called the method twice? That was more difficult than it should've been :D.
You need to login to post a reply.