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 7644943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:48:45+00:00 2026-05-31T09:48:45+00:00

Basically, I am have a basic method for collision detection, and sometimes when I

  • 0

Basically, I am have a basic method for collision detection, and sometimes when I run the applet, it works, but most of the time it doest. Here is the error and some code:

Exception in thread "Thread-3" java.lang.NullPointerException
at zombies.Main.checkCollision(Main.java:110)
at zombies.Main.run(Main.java:140)
at java.lang.Thread.run(Unknown Source)

    public void checkCollision(){
    if(player.playerRect.intersects(platform.platformRect)){ // line 110

        player.dy = 0;
        player.y = (platform.y - player.height);
        player.isTouching = true;
    }

....

    @Override
public void run() {
    try {
        while(true){

        checkCollision(); // line 140
        player.move();

        Thread.sleep(15);

Any help is greatly appreciated! Thanks in advance!

  • 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-31T09:48:46+00:00Added an answer on May 31, 2026 at 9:48 am

    The answer is that either player, player.playerRect or platform is null.

    You would need to break them out into separate checks to figure out exactly which one is null (or stop there with a breakpoint in a debugger).

    To separate out the checks, your code would look something like this:

    if (player == null) {
        throw new NullPointerException("player is null");
    }
    if (player.playerRect == null) {
        throw new NullPointerException("player.playerRect is null");
    }
    if (platform == null) {
        throw new NullPointerException("platform is null");
    }
    

    This will allow you to look at the exception to determine which object is null. You can then examine your code to find out why that object is sometimes set to null, and fix that situation.

    Alternatively, instead of throwing NullPointerExceptions, you can bypass that portion of the code, since maybe it is valid for the object to be null.

    That said, if you are dealing with multiple threads, and the problem only occurs sometimes, you should probably look in to Java’s locking, synchronization and other concurrency tools. Otherwise you might run into a situation where one thread checks to see if an object is null, but after that comparison and before it has a chance to act on the result, another thread alters the object.

    Imagine this sequence of events:

    • Thread A checks and finds that player is not null
    • Thread B runs and replaces player with a null
    • Thread thread A runs, thinking that player is not null, tries to access its playerRect member, but since it is now null, it a NullPointerException is thrown
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

basically, I have a program that has a class to create a basic GUI,
So I have a basic application written in C#. It basically writes a file
I have got a utility class, called ErrorLog , which basically does some basic
I'm sure I'm doing something really dumb and basic here but I can't seem
I basically have a page which shows a processing screen which has been flushed
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp
I basically have something like this: void Foo(Type ty) { var result = serializer.Deserialize<ty>(inputContent);
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a unix process running and it is doing some heavy processing
I basically have a server set up and I'm accepting new clients(UNIX) and i'm

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.