Hey i am making a game in java and while loading the tilesheet I get a weird error and i cant fin out why.
public class TileSheetLoader {
BufferedImage tileSheet;
int width;
int height;
int rows;
int cols;
public BufferedImage[] tiles;
public void loader(int width, int height, int rows, int cols)
{
try
{
ImageIO.read(new File("gfx/tileSheet.png"));
}catch(Exception e){System.out.println("Couldent load tileSheet.png");}
this.width = width;
this.height = height;
this.rows = rows;
this.cols = cols;
this.tiles = new BufferedImage[rows * cols];
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
{
tiles[(i * cols) + j] = tileSheet.getSubimage(i * width, j * height, width, height);
System.out.println("loaded tile");
}
}
}
}
This is the code of the class. I get the NullPointException on this line
tiles[(i * cols) + j] = tileSheet.getSubimage(i * width, j * height, width, height);
this is where i call the methode.
tilesheetloader.loader(96, 32, 1, 3);
already a big thanks for the people who took the time to read.