Why am I getting an InvocationTargetException? Android 2D game

后端 未结 1 1051
误落风尘
误落风尘 2020-12-11 01:07

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
            


        
相关标签:
1条回答
  • 2020-12-11 01:25

    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.

    0 讨论(0)
提交回复
热议问题