The RasterFormatException
is coming from the getSubimage
call here:
h1Walking[i] = sprite1.getSubimage(
i * width + i,
0,
width,
height
);
The getSubimage
method takes x
, y
, width
, and height
as parameters where x and y are the coordinates of the top left pixel of the subimage (from javadoc).
A RasterFormatException
is thrown if the subimage referenced by your parameters is not bounded by the image. So, something in your parameters is out of bounds of the image.
For your x, you are using i * width + i
, but I believe you meant i * width
. This will ensure that each vertical strip of the picture starts where the last one ended.
Additionally, the problem could be that using a constant width and height is giving you an error. Instead, you could consider doing sprite1.getWidth() / h1walking.length
and similar for the height.