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

  • Home
  • SEARCH
  • 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 8549193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:40:15+00:00 2026-06-11T13:40:15+00:00

Well, I’m making a relatively simple platformer game with java and I have a

  • 0

Well, I’m making a relatively simple platformer game with java and I have a method that generates the level, but the tiles won’t draw.

public void generateDungeon() {
    int y = 30;
    for(int x = 0; x < block[0].length; x++) {
        block[x][y] = new Block(new Rectangle(x * Tile.tileSize, y *      Tile.tileSize, Tile.tileSize, Tile.tileSize), Tile.basic);
    }
}

I want the Y to stay the same so that’s why it has a set value.

That is where I think the problem lies, but here’s the console message

Exception in thread "Thread-2" java.lang.NullPointerException
at mineandbuild.Player.isCollidingWithBlock(Player.java:82)
at mineandbuild.Player.tick(Player.java:22)
at mineandbuild.Component.tick(Component.java:89)
at mineandbuild.Component.run(Component.java:110)
at java.lang.Thread.run(Unknown Source)

The console says the problem is at this line of code:

public boolean isCollidingWithBlock(Point pt1, Point pt2) {     
    for(int x = (int) (this.x / Tile.tileSize); x < (int) (this.x / Tile.tileSize  + 3); x++) {
        for(int y = (int) (this.y / Tile.tileSize); y < (int) (this.y / Tile.tileSize  + 3); y++) {
            if(x >= 0 && y >= 0 && x < Component.dungeon.block.length && y < Component.dungeon.block[0].length)
This line --->  if(Component.dungeon.block[x][y].id != Tile.air) {
                if(Component.dungeon.block[x][y].contains(pt1) || Component.dungeon.block[x][y].contains(pt2)) {
                    return true;
                }
            }
        }
    }

    return false;
}

Thanks!

  • 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-06-11T13:40:17+00:00Added an answer on June 11, 2026 at 1:40 pm

    Try printing out the x and y values for

    if(Component.dungeon.block[x][y].id != Tile.air) {
    

    You say that in the code before the value of y should stay the same, which means for every other index of y in the 2-d array they’re set to null, but in the forloop you have this

    for(int y = (int) (this.y / Tile.tileSize); y < (int) (this.y / Tile.tileSize  + 3); y++) {
    

    which leads me to believe that you’re trying to access indices that are null, then trying to access the “id” field, except that that object doesn’t exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, I'm working on an online game in Java. I have a client and
Well, I have a application which somehow requires some system resources, but how do
Well after much messing about I have finally got a query that gives sales
Well im here because i have a problem. i have code that was created
Well, I know there is a lots of posts about it, but I have
Well, I have to revive a question that was answered here before. I've made
Well... simple question, right? But with no so simple answers. In firefox i use
Well, it seems simple enough, but I can't find a way to add a
Well, I have this bit of code that is slowing down the program hugely
Well, i have such-like code that prevent select all action from keyboard: $(document).keydown(function(e){ //

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.