#Why am i getting nullPointerException

10 messages · Page 1 of 1 (latest)

uneven quartz
#
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;

public class Animation {

    // sprite images
    BufferedImage down1, down2, left1, left2, left3, right1, right2, right3, right4, up1, up2;
    public static BufferedImage currentImage;





    public BufferedImage[] createSpriteImages() throws IOException {

        BufferedImage[] spriteImages = {down1, down2, left1, left2, left3,
                right1, right2, right3, right4, up1, up2};


        String[] imagePaths = {"/down1.png", "/down2.png", "/left1.png", "/left2.png", "left3.png",
                "/right1.png", "/right2.png", "/right3.png", "/right4.png", "/up1.png", "/up2.png"};

        for (int i = 0; i < spriteImages.length; i++) {
            spriteImages[i] = new BufferedImage(Map.cellWidth, Map.cellHeight, BufferedImage.TYPE_INT_RGB);
            spriteImages[i] = ImageIO.read(getClass().getResourceAsStream(imagePaths[i]));
        }
        return spriteImages;
    }


}
late juncoBOT
#

This post has been reserved for your question.

Hey @uneven quartz! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

inner torrent
#

isn't spriteImages an array?

#

oh wait nvm

#

it's probably because you didn't initialize the animations object

proud solstice
#

I didn't see mistake Could you help me

dire quartz
# proud solstice

Java, and other typical programming languages, don't support implicit operators.
If you want a multiplication, you must put the multiplication operator.

uneven quartz
#

i fixed it