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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:41:25+00:00 2026-06-02T04:41:25+00:00

Hello and thank you for reading this. I am coding in java/LWJGL. My problem

  • 0

Hello and thank you for reading this. I am coding in java/LWJGL. My problem is that I keep getting a null pointer error with some code if I don’t include this one thing. Basically there are 4 classes

  • A block class.
  • A blockGrid class
  • A blocktype class
  • And a boot class.

The boot class creates a display and in the game loop it runs the draw method that is inside the blockgrid class. To set where a block goes i would use the renderat(x,y) method inside the blockgrid method. The block class just creates a quad at a certain x,y.

Sorry if I’m not explaining good. Here is my code: This is where the error happens just read my comments to see where the error is.

// BlockGrid.java
package minecraft2d;

import java.io.File;

public class BlockGrid {
    private Block[][] blocks = new Block[100][100];

    public BlockGrid() {
        for (int x = 0; x < 25 - 1; x++) {
            for (int y = 0; y < 16 - 1; y++) {
                blocks[x][y] = new Block(BlockType.AIR, -100, -100); //This is where my error happens! If I don't include this line i get a null pointer. Anything will help. I am really stuck and don't know whats happening
            }
        }
    }
    public void setAt(int x, int y, BlockType b) {
        blocks[x][y] = new Block(b, x * 32, y * 32);
    }

    public void draw() {
        for (int x = 0; x < 25 - 1; x++) {
            for (int y = 0; y < 16 - 1; y++) {
                blocks[x][y].draw();
            }
        }
    }
}
  • 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-02T04:41:27+00:00Added an answer on June 2, 2026 at 4:41 am

    The reason you get a NullPointerException when you don’t have that line is that blocks[x][y] will be null for all x,y when draw() is called. draw() assumes you have valid Block objects because it’s calling Block#draw.

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

Sidebar

Related Questions

**Hello, I'm trying to create an archiver in java. This means that I am
Suppose file1 looks like this: bye bye hello thank you And file2 looks like
Hello, thanks for reading my question. I have a string that I need to
I was reading the ctypes tutorial, and I came across this: s = Hello,
Hello all and thanks for your time reading this. I need to verify certificates
For some reason in the testEmployee method I am getting weird error messages saying
Given a yaml file that contains html , like this: template : |+ <div>Hello,
Hello I was reading this question, I got confused with how if we can
I am new to Hibernate, reading this book Java persistence with Hibernate and I
Hello folks and thanks in advance for reading this. I currently use a slider

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.