So I'm making a game for a friend. A fairly simple thing, and I'd like to put everything (class files and a few PNGs) in a JAR. No problem.
Except it doesn't work. The program will run just fine, but the images don't show up. A small tweak (using a URL object to load the image) and it crashes:
Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:97)
at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:107)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:240)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
That error pops up whether it's JARed or not...
I'm not familiar with the URL class, but I suspect this error is because I'm not actually doing anything internet related.
So... what hoops do i have to jump through to get at my PNG? I looked around online a bit and my question doesn't seem to be answered anywhere. I suspect that I'll have to open the jar like a compressd file (yes i know, it is) and read my PNG like that. Isn't there be an easier way? One that doesn't care if the program is running as a bunch of class files in a directory or in inside a jar?
EDIT: OK, I tracked down the source of the NullPointerException... java.lang.Class's getResourse(String) method is returning a null instead of a URL...
EDIT: ACK!!!! *facepalm repeatedly* I'm an idiot... it was all caused by a FREAKING TYPO! It works fine now now... *locks the thread*