I have a simple enum called Tile that merely keeps track of the images an individual tile uses. I then have a Chunk class that contains a Tile array which stores individual tiles. The Chunk makes a call to a ChunkBuilder class which generates a Tile array in an island formation. Next, I have a World class which has a Chunk array so that I can render the chunks and create the world. To test and make sure this all worked I added a Chunk array requirement to the constructor for the world class; I then created a simple for-loop in my GameState class to create a Chunk array which is then supplied to the World object. Now, this all works perfectly fine and everything renders well.
Now, to the problem; I have created a WorldBuilder class with the task of generating a Chunk array to make the Chunks much more random and allow water Chunks to space out the islands for a much nicer look. This is just a quick example of how it looks:
public WorldBuilder() {
chunks = new Chunk[8][8];
}
public Chunk[][] generateWorld() {
for (int i = 0; i > chunks.length; i++) {
for (int j = 0; j > chunks[0].length; j++) {
if (Math.random() > 0.5) {
chunks[j][i] = new Chunk(true);
} else {
chunks[j][i] = new Chunk(false);
}
}
}
return chunks;
}
My World constructor then looks something like this:
public World() {
chunks = new WorldBuilder().generateWorld();
}
When I run my game, it crashes with a null pointer exception. So, I decided to write a simple for-loop to go through the World object and print out in the console what exactly is stored in the World’s Chunk array. When I run my game null is printed to the console for each index.
Would anyone happen to have any ideas as to why? Thanks!