0

I'm currently in the process of developing a game for OUYA using android java and ODK. when checking for collisions my game crashes out and returns to the menu. This is the point at which things bug out:

    private void checkCollision() {
    if (Rect.intersects(bulletRect1, enemyRectOne1)) {
        visible = false;
    }
}

both Rects are working fine as when I paint them on screen and comment out this method they display as they should. visible = false works fine in other methods within the class. Have I made a mistake somewhere or have other people come across this?

EDIT fixed now. Hunted through my entire code searching for where a Rect could be set to null. Turns out 2 versions of the same Rect were being created, 1 of which was probably null. Many thanks for the support.

  • 1
    do you have a stack trace? – Tom Jul 23 '13 at 12:04
  • basically this method kills my run method: Thread [<14> Thread-288] (Suspended (exception NullPointerException)) GameScreen$GameThread.run() line: 489 – Sahoskins12 Jul 23 '13 at 12:16
  • Great! Now, I spy a NullPointerException, humour me terribly here, but there's no smoke without fire. Have you checked anything dereferenced on that line is not null? – Tom Jul 23 '13 at 12:19
  • put an if statement in checking for not null and still bugs out exactly the same – Sahoskins12 Jul 23 '13 at 12:24
  • Have you checked bulletRect1 *and* enemyRectOne1, and is what you've posted line 489? – Tom Jul 23 '13 at 12:40
  • checked both. and no, all that is on line 489 is the final } in run() which is my game loop in a separate class however LogCat shows that the intersects statement is where it falls over and run() works fine when I comment out the section that I posted. – Sahoskins12 Jul 23 '13 at 12:50

1 Answers1

0

2 versions of the same Rect were being created in earlier code, 1 of which was probably null. Simple mistake but very costly time wise.