1

First off let me start by stating what my project path looks like really quickly.

project/src/application/<.java files>
project/src/img/<.png files>
project/bin/application/<.class files>
project/bin/img/<.png files>

Eclipse was smart enough to duplicate my img folder in the bin folder once I created under the src folder.

The code in question is the following (called in the CardImage class):

BufferedImage myPic = ImageIO.read(CardImage.class.getClass().getResource("/img/1.png"));

From what I can tell, this is the correct way of grabbing the images off the bin/img folder. Yet I continue to get the following error.

javax.imageio.IIOException: Can't read input file!
    at javax.imageio.ImageIO.read(Unknown Source)

I've read similar questions and answers such as this one but can't seem to figure out why it's not working. Also I'm not entirely sure if the getClass() call was necessary after doing

CardImage.class
H K
  • 31
  • 1
  • 5
  • I am really sorry for the late reply. Was a bit offline for a long long time, with my own thingies. Do try to follow these steps, as mentioned [here](http://stackoverflow.com/a/9278270/1057230). If it still not working, please do let me know. Many apologies for being late. – nIcE cOw Nov 28 '15 at 01:41
  • It doesn't work. I even wondered if having my code in a package might be causing the problem. – H K Nov 30 '15 at 01:11
  • It doesn't work. I even wondered if having my code in a package might be causing the problem but that's not it. Currently my path looks as [such](http://imgur.com/WPVGwRZ). The code for grabbing these is `java.net.URL picURL = CardImage.class.getClass().getResource("/img/" + ((15 - c.getRankInt()) * 4 - suit) + ".png"); ii = new ImageIcon(picURL);` – H K Nov 30 '15 at 01:18
  • Now it doesn't run when I export to a jar file AND it also doesn't work when I try to run off eclipse. [This](http://imgur.com/DZHttkS) is what it looks like if I look at the root of the jar file. The img folder has the correct images inside it. – H K Nov 30 '15 at 01:25
  • Have you created a source folder, as mentioned, and then added `img` folder to it and inside this `img` folder, the images for the project !!!!! – nIcE cOw Nov 30 '15 at 02:45
  • OMGGGGGGGGGGGGGG. The... there was another piece of code that was getting the images but it used the old `new File` syntax to do it (I didn't know any better back then)... This meant that even when I got everything else right, it still wouldn't run in an executable jar file. It also explains why I could run the program on eclipse with certain file configurations... Oh man, this is what I get for not reading the errors properly... Almost a month and a half lost to misread error that I never bothered reading after the first time. Sigh... Thank you SO MUCH. – H K Dec 03 '15 at 22:04

0 Answers0