I am using IntelliJ to build a .jar of my project, but whenever i call any of the following:
getClass().getClassLoader().getResourceAsStream();
getClass().getClassLoader().getResource();
getClass().getResource();
getClass().getResourceAsStream();
I ALWAYS get this error:
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1358)
at Objects.Collsion.TexturedBarrier.setTexture(TexturedBarrier.java:34)
at Objects.Collsion.TexturedBarrier.<init>(TexturedBarrier.java:20)
at Levels.Menu.MainMenu.load(MainMenu.java:21)
at Levels.Level.loadLevel(Level.java:36)
at Main.GamePanel.nextLevel(GamePanel.java:127)
at Main.GamePanel.setStage(GamePanel.java:108)
at Main.GamePanel.<init>(GamePanel.java:28)
at Main.Game.main(Game.java:23)
The class causing the error is:
public class TexturedBarrier {
protected BufferedImage currentTexture;
public TexturedBarrier(String texture) {
setTexture(texture);
}
public void setTexture(String texture) {
InputStream stream = this.getClass().getClassLoader().getResourceAsStream(texture);
try {
currentTexture = ImageIO.read(stream);
}catch (IOException e) {e.printStackTrace();}
}
}
And the code calling it is:
new TexturedBarrier("Play!_Background_green.jpg");
The resource folder is set as a resource root in IntelliJ, and the resource folder is as follows: res folder
and after using 7zip to inspect the jar, the file is definately in the jar: inside jar
Any ideas? i know this is an issue with alot of similar questions, but none of the solution posed have helped me.