tags:

views:

48

answers:

3

Hello,

created a new folder "resources" with all my images in eclipse. I added this folder to the class path.

Now i tried to access this images

URL url = new URL("imageA");

I also tried

URL url = new URL("resources/imageA");

Both doesnt't work. What is wrong?

Sincerely Christian

A: 

If you are loading from your classpath you should do something like this

InputSteam is =  this.getClass().getClassLoader().getResourceAsStream("resources/myimage.png")
Chuk Lee
A: 

See here for directions. You can't load an image directly with URL (actually you can, but it is complicated see this question)

Actually you need to do something like this:

ClassLoader loader = ClassLoader.getSystemClassLoader();

if(loader != null) {
   URL url = loader.getResource(name);
}
kgiannakakis