I get an ArrayIndexOutOfBoundsException, but only when the getSubImage() function is there.
This is to loop through and get sprites.I've tried it without getsubimage and i've tried using different for loops though nothing has helped.
This is not the same as the thread I am being compared to, as I am using a for loop inside of another. The program works just fine without getSubimage, and the for loops work just fine. I do not know where the problem lies or what it is.
try {
BufferedImage spritesheet = ImageIO.read(
getClass().getResourceAsStream(
"/Sprites/SpriteSheet.gif"
)
);
sprites = new ArrayList<BufferedImage[]>();
for(int i = 0; i < 6; i++) {
BufferedImage[] bi =
new BufferedImage[i];
for(int j = 0; j < numFrames[i]; j++) {
bi[j] = spritesheet.getSubimage(
i * width,
j* height,
width,
height
);
}
sprites.add(bi);
}
}
catch(Exception e) {
e.printStackTrace();
}
I expect it to loop through this and get all the sprites. What actually happens is it doesnt get the subimage and it just throws an out of bounds exception.