This might be a dumb question, but why am I getting a null pointer exception here? I am trying to paint a tile map for a java applet. I just pasted the problem areas.
private int[][] map;
public void init()
{
int map[][]={ {0,0,0},
{1,1,0},
{0,0,0} };
}
public void drawCaveTiles(Graphics g)
{
for(int i = 0; i <= 3; i++)
{
for( int j = 0; j <= 3; j++)
{
if(map[i][j] == 1)
{
g.drawImage(snow_brick, i*64, j*64, this);
}
if(map[i][j] == 0)
{
g.drawImage(black, i*64, j*64, this);
}
}
}
}
I fixed it
map =new int[][] { {0,0,0},
{1,1,0},
{0,0,0} };
iandjinsidedrawImageis wrong.iis the row of your array and therefore is the y coordinate andjis the column and so the x coordinate. If you already consider the difference between row, x coordinate and column, y coordinate by working with a transposed array see this comment as neglectable.