java.lang.IllegalArgumentException: input == null! when using ImageIO.read to load image as bufferedImage

前端 未结 10 1988
予麋鹿
予麋鹿 2020-11-27 22:14

This is a question that has been asked like 100 times on this site, but I have looked at all of them and even though they all were solved, none of the solutions worked for m

10条回答
  •  臣服心动
    2020-11-27 22:50

    I had the exact same problem. I used the path "my_image.png" at first but it did not work, so I searched everywhere and tried the other solutions posted on this site but none of them worked. I solved mine by changing my code from this

     image = ImageIO.read(SpriteSheet.class.getResourceAsStream("res/image.png"));
    

    to this

     image = ImageIO.read(SpriteSheet.class.getResourceAsStream("/image.png"));
    

    I hope this helps, even though this question was posted 5 years ago.

提交回复
热议问题