Reputation: 154
When I try reading the image from my res folder, I get this error:
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at SpritePractice.render(SpritePractice.java:103)
at SpritePractice.run(SpritePractice.java:71)
at SpritePractice.start(SpritePractice.java:123)
at SpritePractice.main(SpritePractice.java:131)
The image itself (MarioSpriteSheet.png) is in the res folder, and I spelled the name right. What's the problem here?
BufferedImage spriteSheet = new BufferedImage(WIDTH*2,HEIGHT*2, BufferedImage.TYPE_INT_RGB);
try
{
spriteSheet = ImageIO.read(getClass().getResourceAsStream("/res/MarioSpriteSheet.png"));
}catch (IOException e)
{
e.printStackTrace();
}
finally
{
pixelsFromImage = ((DataBufferInt) spriteSheet.getRaster().getDataBuffer()).getData();
}
Upvotes: 1
Views: 3094
Reputation: 33033
Omit /res/
from the filename. If res
is on the CLASSPATH you shouldn't need it.
Upvotes: 2