K
kempshall
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
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