Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7093513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:26:55+00:00 2026-05-28T08:26:55+00:00

I am making a 2D game in Android with Cocos2D, written in Java. Here

  • 0

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(0, 6)) {
        guy.moveY(6);
    }

    //Player Movement
    if(direction == 1) {
        if(canExecuteMovement(-3, 0))
            guy.moveX(-3);
    } else if(direction == 2) {
        if(canExecuteMovement(3, 0))
            guy.moveX(3);
    }
}

private boolean canExecuteMovement(int xChange, int yChange) {
    int projectedX = guy.getBounds().left + xChange;
    int projectedY = guy.getBounds().top + yChange;
    Log.i("DD", "guy:" + guy.getBounds().toString());
    Rect projectedBounds = new Rect(projectedX, projectedY, projectedX + guy.getWidth(), projectedY + guy.getHeight());
    Log.i("DD", "guy:" + projectedBounds.toString());
    for (int i = 0; i < platformCount; i++) {
        if (Rect.intersects(projectedBounds, platform[i].getBounds())) {
            return false;
        }
    }

    return true;
}

As you see, this function looks just fine, and the rectangles in canExecuteMovement are perfectly fine too, however in this line:

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

I am getting a InvocationTargetException. Here is the logcat:

01-21 23:10:12.601: W/System.err(13118): java.lang.reflect.InvocationTargetException
01-21 23:10:12.601: W/System.err(13118):    at java.lang.reflect.Method.invokeNative(Native Method)
01-21 23:10:12.605: W/System.err(13118):    at java.lang.reflect.Method.invoke(Method.java:511)
01-21 23:10:12.605: W/System.err(13118):    at org.cocos2d.actions.CCTimer.update(CCTimer.java:82)
01-21 23:10:12.605: W/System.err(13118):    at org.cocos2d.actions.CCScheduler.tick(CCScheduler.java:253)
01-21 23:10:12.605: W/System.err(13118):    at org.cocos2d.nodes.CCDirector.drawCCScene(CCDirector.java:679)
01-21 23:10:12.605: W/System.err(13118):    at org.cocos2d.nodes.CCDirector.onDrawFrame(CCDirector.java:649)
01-21 23:10:12.605: W/System.err(13118):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
01-21 23:10:12.605: W/System.err(13118):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
01-21 23:10:12.605: W/System.err(13118): Caused by: java.lang.NullPointerException
01-21 23:10:12.608: W/System.err(13118):    at com.qasim.platformer.GameLayer.canExecuteMovement(GameLayer.java:107)
01-21 23:10:12.608: W/System.err(13118):    at com.qasim.platformer.GameLayer.gameLoop(GameLayer.java:86)
01-21 23:10:12.608: W/System.err(13118):    ... 8 more
01-21 23:10:12.620: D/dalvikvm(13118): GC_CONCURRENT freed 460K, 6% free 9279K/9863K, paused 2ms+3ms
01-21 23:10:12.624: I/DD(13118): guy:Rect(252, 63 - 300, 111)

What could be the problem? the getBounds() class in guy is this:

public Rect getBounds() {
    return new Rect(x, y, x+width, y+height);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:26:56+00:00Added an answer on May 28, 2026 at 8:26 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple Android game written in Java. I have my activity... public
I'm making a game to run on android. So I want to store player
I am making a game in JAVA where I want to come up with
I'm making a game. Now if my player goes to another level the music
I'm making a scrolling game on Android and am having a hard time figuring
I'm making a simple 2d game for the android platform, which works perfectly from
For a 2D game I'm making (for Android) I'm using a component-based system where
I am making a 2D game for the Android platform. The character is supposed
I'm making my first Android game which is going to be a 3D arcade-ish
I'm new to Android programming and I am making a game. My problem is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.