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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:44:14+00:00 2026-05-28T13:44:14+00:00

I’ve been searching a lot for this problem and I can’t find a solution.

  • 0

I’ve been searching a lot for this problem and I can’t find a solution. I’m trying to build a mini-game and I have a method for creating platforms. I have a class with every platform parameters, and I made a class array so i can have multiple platforms at the same time.

Problem: When I try to call the method for constructing the platform by sending the parameters I want, it gives me a NullPointerException. The method was working before, but with everything static and so i couldnt have multiple instances of that class, and now I removed the static fields from the platform class and it gives me the NullPointerException every time I call the method.

I copied the part of the code that gives me the error, the error goes the following way:

public static void main(String[] args) {
        Game ex = new Game();
        new Thread(ex).start();
    }

In Game class:

public Load_Stage load = new Load_Stage();
public Game() {
        -other variables initializatin-
        Initialize_Items();
        load.Stage_1(); // <--- problem this way

In Load_Stage class:

public class Load_Stage {
    public Platforms plat = new Platforms();

    public void Stage_1(){    
        Stage_Builder.Build_Platform(200, 500, 300, plat.platform1);
        Stage_Builder.Build_Platform(100, 200, 100, plat.platform1);
    }

}

And inside the Stage_Builder class:

public class Stage_Builder {

    public static final int max_platforms = 10;
    public static Platform_1[] p1 = new Platform_1[max_platforms];
    public static boolean[] platform_on = new boolean[max_platforms];    

    public Stage_Builder() {
        for (int c = 0; c < platform_on.length; c++) {
            platform_on[c] = false;
        }
    }
    public static void Build_Platform(int x, int y, int width, ImageIcon[] type) { // BUILDS A PLATFORM

        for (int b = 0; b < max_platforms; b++) {
            if (platform_on[b] == false) { 
                p1[b].Construct(x, y, width, type); // <-- NullPointerException here
                platform_on[b] = true; 
                break;
            }
        }
    }
}

Thanks beforehand.

EDIT: Here’s the Platform_1 class (sorry for forgetting about it):

public class Platform_1 {

    private int platform_begin_width = 30;
    private int platform_middle_width = 20;
    public int blocks_number = 0;
    public ImageIcon[] platform_floors = new ImageIcon[500];
    private int current_width = 0;
    public int [] platform_x = new int [500];
    public int platform_y = 0;
    public int platform_width = 0;

    public void Construct(int x, int y, int width, ImageIcon [] type) {        
        platform_width = width;
        platform_y = y;
        for (int c = 0; current_width <= platform_width; c++) { 
            if (c == 0) {
                platform_x[c] = x;
                platform_floors[c] = type[0];
                current_width += platform_begin_width;
            } else if ((current_width + platform_middle_width) > platform_width) {
                platform_floors[c] = type[2];
                blocks_number = c + 1;
                platform_x[c] = current_width + x;
                current_width += platform_middle_width;
            } else {
                platform_floors[c] = type[1];
                platform_x[c] = current_width + x;
                current_width += platform_middle_width;
            }
        }        
    }
}

And the Platforms class:

public class Platforms {

    public ImageIcon[] platform1 = {new ImageIcon("Resources/Sprites/Stage_Objects/Platform1/begin.png"),
        new ImageIcon("Resources/Sprites/Stage_Objects/Platform1/middle.png"),
        new ImageIcon("Resources/Sprites/Stage_Objects/Platform1/end.png")};
}
  • 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-28T13:44:15+00:00Added an answer on May 28, 2026 at 1:44 pm

    The problem and solution are both obvious.

    public static Platform_1[] p1 = new Platform_1[max_platforms];
    

    After this line of code executes, p1 is an array of references of type Platform_1 that are all null.

    Executing this line of code tells you so right away:

                p1[b].Construct(x, y, width, type); // <-- NullPointerException here
    

    The solution is to intialize the p1 array to point to non-null instances of Platform_1.

    Something like this would work:

    for (int i = 0; < p1.length; ++i) {
        p1[i] = new Platform1();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.