Here is the code that I am using:
/**
* This method loads an image
*
* @param path - path of the image
*
*
*/
public static BufferedImage loadImage(String path) {
try {
return ImageIO.read(ImageLoader.class.getClass().getResourceAsStream(path));
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
return null;
}
Here is the error:
Exception in thread "Thread-2" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at io.deadspace.graphics.ImageLoader.loadImage(ImageLoader.java:19)
at io.deadspace.graphics.asset.assets.EntityAssets.initEntityAssets(EntityAssets.java:15)
at io.deadspace.graphics.asset.Assets.init(Assets.java:37)
at io.deadspace.Game.init(Game.java:73)
at io.deadspace.Game.run(Game.java:127)
at java.lang.Thread.run(Unknown Source)
I recently re-did the way I loaded images into my game, it worked fine before, but now, it doesn't work anymore. I've tried both getResource and getResourceAsStream.
Here are some examples of how I am loading the images:
public void initEntityAssets() {
sheet = new SpriteSheet(ImageLoader.loadImage("res/textures/sheet.png"));
wood = sheet.crop(width, height, width, height);
tree = sheet.crop(0, 0, width, height * 2);
rock = sheet.crop(0, height * 2, width, height);
rockDropItem = sheet.crop(1, height * 2, width, height);
}
public void initHotbarAssets() {
sheet = new SpriteSheet(ImageLoader.loadImage("res/textures/sheet.png"));
hotbar = sheet.crop(0, height * 4, width, height);
hotbar_selected = sheet.crop(0, height * 5, width, height);
}