tags:

views:

209

answers:

1

I was loading an image resource with the following code and it works fine from my dev environment (netbeans) but threw an exception as soon as it ran from the desktop.

new ImageIcon(Images.class.getResource("images/highlighter24.gif"));

I traced it down to my file having different case than in the code.

Fine, my bad, but why the inconsistent behavior?

Gremlins?

Note: I'm running on windows before you ask.

+8  A: 

Let me guess: in NetBeans it was loading it from the file system (which is case-insensitive) whereas when running it from the desktop it was in a jar file (which is case-sensitive).

I've seen this kind of thing before, where a web app worked fine on Windows but failed on Unix because we'd got the case wrong in the URL.

If you think of jar files as "just another file system" then it makes sense, even if it's slightly annoying to have the inconsistency.

Jon Skeet
Not sure if this correct, but it would explain why I can build my app while another has supposedly locked the jar files.Damn you netbeans! jk
Allain Lalonde
Easy way to find out whether or not it's correct: print out Images.class.getResource("images/highlighter24.gif") - if shows as a file://[...] in NetBeans and a jar://[...] on the desktop, then that's good evidence :)
Jon Skeet