Skip to content Skip to sidebar Skip to footer

Why Am I Getting An Invocationtargetexception? Android 2d Game

I am making a 2D game in Android with Cocos2D, written in Java. Here is my code for the main stuff: public void gameLoop(float dt) { //Player Gravity if(canExecuteMovement(

Solution 1:

InvocationTargetException is just a wrapper for an exception that's thrown within a dynamic invocation. The true problem is the NullPointerException that it's wrapping:

Caused by: java.lang.NullPointerException
  at com.qasim.platformer.GameLayer.canExecuteMovement(GameLayer.java:107)
  at com.qasim.platformer.GameLayer.gameLoop(GameLayer.java:86)

As you've pointed out, this is the offending line:

if (Rect.intersects(projectedBounds, platform[i].getBounds())) {

The only place a null pointer could be happening on this line is at platform[i].getBounds(). Either platform itself is null, or the element at platform[i] is.

Post a Comment for "Why Am I Getting An Invocationtargetexception? Android 2d Game"