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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:56:13+00:00 2026-06-18T12:56:13+00:00

This may be a stupid question, but I’m getting sick of this. How do

  • 0

This may be a stupid question, but I’m getting sick of this. How do you properly initialize a class object so you can access methods and variables in it? Here’s my code:

public class GenChunk {

Chunk c;
VBO vbo;

int worldSize = 64;
int var1 = 16; //x
int var2 = 16; //z
int var3 = 16; //y

public GenChunk(){
    gen();
}

public void gen(){
    c = new Chunk();
    if(c.chunkChanged == false){
        for(int i = 0; i < worldSize; i++){
            newChunk();
        }
    }
}

The line c = new Chunk() is causing the stack overflow error., I realize why (because its creating new instances of it and taking up more and more memory), but as soon as I initialize it in the constructor or just do Chunk c = new Chunk(), at the top below public class GenChunk { I get another stack overflow error! If I don’t initalize the class, I get a null pointer (obviously). What is wrong with my code? I must be overlooking something, but I can’t figure it out!

Here is my Chunk class, it has a few empty methods:

public class Chunk {

public boolean chunkChanged = false;
boolean enteredGame = true;

public int chunkID = 0;

Player player;

float var1;
float var2;
float var3;

public Chunk(){
    update();
}

private void update(){
    setUp();
}

private void setUp(){
    if(enteredGame){
        new GenChunk();
    }
}

private void checkChunkRebuild(int id){

}

private void rebuildOnPlayerChange(int id){
    if(enteredGame && chunkChanged == true){

    }
}

private float getPlayerX(){
    return player.var1;
}

private float getPlayerZ(){
    return player.var2;
}

private float getPlayerY(){
    return player.var3;
}

}

  • 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-18T12:56:14+00:00Added an answer on June 18, 2026 at 12:56 pm

    Your Chunk class is creating a new instance of GenChunk, which in turn is creating a new instance of the Chunk class, creating an infinite loop until the stack overflow occurs.

    private void setUp(){
    if(enteredGame){
        new GenChunk();
        }
    }
    

    is where it starts, and it continues at

    public void gen(){
        c = new Chunk();
    if(c.chunkChanged == false){
        for(int i = 0; i < worldSize; i++){
            newChunk();
        }
      }
    }
    

    which is called in the GenChunk constructor.

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

Sidebar

Related Questions

This may sound like a stupid question but I can't seem to find an
This may sounds like a stupid question but can't find anything on google, probably
This may be a stupid question but I can't help asking, just to verify.
This may seem a stupid question but I can't find the anwer... This is
This may sound very stupid question , but I can't find any documentation that
This may be a stupid question but I can't seem to figure this out.
This may sound like a stupid question, but how can I start to use
This may be a stupid question but I just can't find the answer. What
This may be a stupid question, but I can't find an answer... I'm sending
This may seem like a stupid question, but i can't quite remember how to

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.