Can't create a runnable jar with Intellij Idea
This question already has an answer here:
As far as I can see the problem is not in the jar export, but in your code:
In your method BufferedImageLoader.loadImage(String path)
(in the file BufferedImageLoader.java at line 15) you call ImageIO.read(InputStream input)
. And you pass it a null object returned by Class.getResourceAsStream(path)
, and as the docs for ImageIO.read(InputStream input)
state:
Throws: IllegalArgumentException - if input is null.
This causes a IllegalArgumentException. I recommend using this code:
public class BufferedImageLoader {
private BufferedImage image = null;
public BufferedImage loadImage(String path) {
try {
return image = ImageIO.read(BufferedImageLoader.class.getResourceAsStream(path));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
See this post for more info.
链接地址: http://www.djcxy.com/p/76198.html上一篇: 在Java中表示分数的最佳方式是什么?