Can somebody explain how the Class.getResource method constructs its
absolute name? In particular, I have a directory setup like this:
root
|____classes
| |______myPackage
| |__________myApp.class
|____img
|______myImage.gif
I run my application with classes as my current working directory,
using the command java -classpath . myPackage.myApp, and I want to use
the getResource method to load myImage.gif like this: Image myImg =
Toolkit.getDefaultToolkit().getImage(getClass().getResource(/path/to/myImage.gif))....
but everything I've tried putting into /path/to/myImage.gif results in
some sort of Resource Not Found error. According to the Java
documentation, I should use something like
getResource(/../../img/myImage.gif) or without the leading slash,
getResource(../../../img/myImage.gif), but neither of those work. Can
anybody help me figure out what will work?
Thanks,
Jay
Robert - 04 Jan 2006 02:16 GMT
When we do that we put the file somewhere under the classes dir and the
use "/filename" to find it. Hope this helps.
Chris Smith - 04 Jan 2006 03:39 GMT
> root
> |____classes
[quoted text clipped - 13 lines]
> getResource(../../../img/myImage.gif), but neither of those work. Can
> anybody help me figure out what will work?
Nothing will work. Resources need to be placed within the classpath,
which means somewhere in the classes directory. Move it there, and your
problem is solved.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation