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

2015/12/14

getOneIntersectingObject question

ddanellakis ddanellakis

2015/12/14

#
Hello everyone! I construct several actors, I place them on my world at random points, then I want to check if they are touching any other actors previously placed on the world. and if so, I want to move them until they are no longer touching anything else. This is the method I wrote in all my actor classes, and I call it from my world, right after any addObject that I do: public void myCheckTouch() { while (getOneIntersectingObject(null) != null) { move(1); } } The "while" line of code throws a NullPointerException. Why?
fejfo fejfo

2015/12/14

#
yous shoudn't use :
getOneIntersectingObject(null) 
but
getOneIntersectingObject(Actor.class)
danpost danpost

2015/12/14

#
fejfo wrote...
yous shoudn't use :
getOneIntersectingObject(null) 
but
getOneIntersectingObject(Actor.class)
Either the API documentation on the method is incorrect or it does not function as the API documentation says it should. The suggestion given by fejfo is sufficient to avoid the issue.
ddanellakis ddanellakis

2015/12/14

#
Ok, I will try that, thank you. Although, as danpost says, I passed null as argument to getOneIntersectingObject because the Greenfoot manual says so. :)
You need to login to post a reply.