javax.imageio.IIOException: Can't read input file!

That is the error I get every time I try to run the .jar file. Yet when I run it in the compiler it works just fine. I'm not sure what to make of this, here is the code any help you can provide will be appreciated.publicvoid setGraphic(String image){

String fileLoc = getClass().getResource("/com/siteName/Graphics/" + image).getPath();

try{

fileLoc = URLDecoder.decode(fileLoc,"UTF-8");

}catch (UnsupportedEncodingException ex){

ex.printStackTrace();

}

File file =new File(fileLoc);

try{

this.image = ImageIO.read(file);

}catch (IOException ex){

ex.printStackTrace();

}

}

[1208 byte] By [drawimagea] at [2007-11-27 10:51:28]
# 1

Is your image *in* the jar? If so, use URL, not File:

URL url = getClass().getResource("/com/siteName/Graphics/" + image);

this.image = ImageIO.read(url );

BigDaddyLoveHandlesa at 2007-7-29 11:31:19 > top of Java-index,Java Essentials,Java Programming...
# 2

Thank you so much, this was baffling me badly.

drawimagea at 2007-7-29 11:31:19 > top of Java-index,Java Essentials,Java Programming...
# 3

This code also works if the app is not jarred. So one should always do it using URLs, not File objects.

BigDaddyLoveHandlesa at 2007-7-29 11:31:19 > top of Java-index,Java Essentials,Java Programming...