Your error is that you are shadowing a variable -- you're re-declaring the variable tileSet inside constructor when it was already declared in the class. Thus the tileSet variable declared in the class is never initialized since only the local variable, the one declared in the constructor is initialized.
The solution: Only declare tileSet once, in the class.
Thus, don't do this:
public class TileList extends JPanel {
//.... deleted for brevity
BufferedImage tileset[];
public void loadAndSplitImage (File loadImage) {
try{
image = ImageIO.read(loadImage);
}catch(Exception error) {
System.out.println("Error: cannot read tileset image.");
}// end try/catch
col = image.getWidth()/width;
row = image.getHeight()/height;
BufferedImage tileset[] = new BufferedImage[col*row]; // *** re-declaring variable!
}
but instead do this:
public class TileList extends JPanel {
//.... deleted for brevity
BufferedImage tileset[];
public void loadAndSplitImage (File loadImage) {
try{
image = ImageIO.read(loadImage);
}catch(Exception error) {
System.out.println("Error: cannot read tileset image.");
}// end try/catch
col = image.getWidth()/width;
row = image.getHeight()/height;
// ************
// BufferedImage tileset[] = new BufferedImage[col*row]; // *****
tileset[] = new BufferedImage[col*row]; // **** note the difference? ****
}
Note that even more important than the solution for this isolated problem is to gain an understanding on how to solve NPE (NullPointerExceptions). The key is to check all the variables on the line throwing the exception, check to see which one(s) is null, and then look back to see where one of them is not being initialized properly before you try using it.