I'm currently working on some code, and still being a beginner in java, i'm having a little trouble figuring out this problem, and would like to get some advice on what I did wrong, and can do to fix it.
The code that will be below throws me a null pointer exception on the line where the entry in the array is added in the loop
public class World {
int mapWidth;
int mapHeight;
Tile testTile;
Tile[][] map;
public World(int width, int height)
{
testTile = new Tile(0,0, 100);
mapWidth = width;
mapHeight = height;
}
public World()
{
mapWidth = 10;
mapHeight = 10;
testTile = new Tile(0,0, 100);
}
public void generate()
{
for(int y = 0; y <= mapHeight; y++)
{
System.out.println("Y: " + y);
for (int x = 0; x <= mapWidth; x++)
{
System.out.println("X: " + x);
map[x][y] = new Tile(x, y, 100);
}
}
}
public void render(SpriteBatch batch)
{
}
}
Any advice is greatly appreciated, thanks for any help that you can give!