简体   繁体   English

ImageIO.read(getClass()。getResource(imgStr))在JAR中返回null

[英]ImageIO.read(getClass().getResource(imgStr)) returns null in JAR

I am having an issue loading images in my JAR file. 我在JAR文件中加载图像时遇到问题。 I am using : 我在用 :

BufferedImage img = ImageIO.read(getClass().getResource(imgStr));

Where imgStr is of the form "/xxxx.png". 其中imgStr的格式为“ /xxxx.png”。

I have two different .png images in the same location. 我在同一位置有两个不同的.png图像。 One image, let's say /x.png loads fine. 假设一张图片/x.png可以很好地加载。 The other image, /y.png give the error: 另一个图像/y.png给出错误:

java.lang.IllegalArgumentException: input == null

I can't find any reason for this. 我找不到任何原因。 Strangely, the everything works fine in the Eclipse environment. 奇怪的是,一切在Eclipse环境中都能正常工作。

Could it have something to do with the images being transparent? 它与透明的图像有关吗?

Does anyone have an idea?? 有人有主意吗?

Thanks in advance. 提前致谢。

So the issue was that some of the files were .PNG in capitals. 因此,问题在于某些文件是大写的.PNG文件。 Apparently some programs save as ".png" and others as ".PNG". 显然,某些程序另存为“ .png”,另一些程序另存为“ .PNG”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM