Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to detect a collision between an AnimatedSprite and the Rectangle floor. When they collide, I want the sprite to be removed. However, I keep getting a null pointer error. Am I doing this the wrong way?

Inside my add face function. face is an AnimatedSprite created, and ground is a rectangle.

this.mScene.registerUpdateHandler(new IUpdateHandler() {
            public void reset() { }

            public void onUpdate(final float pSecondsElapsed) {
                    if(face.collidesWith(ground)) {

removeFace() is:

private void removeFace(final AnimatedSprite face) {
    final PhysicsConnector facePhysicsConnector = this.mPhysicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(face);




The null pointer exception is inside removeFace()

share|improve this question
up vote 2 down vote accepted

Look at the stack trace it will tell you exactly which line has the null pointer exception. You need to invest in learning to use the debugger too, these are simple problems to debug and you can solve your own problems much faster than waiting for a reply here.

From your code I'm assuming that


is returning null because it's unable to find the face you specify. So it could easily throw a null pointer exception when it reaches: facePhysicsConnector.getBody(). Since you can't access a method of a null object.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.