简体   繁体   中英

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

I am having an issue loading images in my JAR file. I am using :

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

Where imgStr is of the form "/xxxx.png".

I have two different .png images in the same location. One image, let's say /x.png loads fine. The other image, /y.png give the error:

java.lang.IllegalArgumentException: input == null

I can't find any reason for this. Strangely, the everything works fine in the Eclipse environment.

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. Apparently some programs save as ".png" and others as ".PNG".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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