Problem loading images - please help

Hi,

I have a slight problem loading images. I'm using netbeans 5.0 and have a few packages setup in a project called Maths. In a package called LineConnection theres a class that needs to read an image and display it on screen. To load the image I use:

URL url = getClass().getResource("fraction/pic1.png");

Image img1 = Toolkit.getDefaultToolkit().getImage(url);

This loads the image and I can display it on screen fine.

The problem is that the folder fractions with the images inHAS to be located within the Maths/build/class/LineConnection folder otherwise it wont load the image and I get a null pointer exception.

I want to be able to have the folder containing the images in folder Maths so that it's one folder above the src folder. But if I put it here (or anywhere else) the images can't be found and loaded.

Could someone tell me why the images can only be found if they're within the build folder because it's causing me some problems when I try to create an executable JAR.

Cheers

[1085 byte] By [uraknaia] at [2007-10-3 3:10:45]
# 1

I've used:

URL url = ImageHandler.class.getResource("fractions/q0.png");

System.out.println("URL = " + url);

to determine whether the file is found.

If I put the file in the folder build/classes/LineConection/fractions/q0.png then it finds the image and prints the file path.

But, if I put it in another folder such as the src folder it can't find the image and url = null;

How can I make netbeans search in other folders for the resources so I can store them where I like?

uraknaia at 2007-7-14 21:01:33 > top of Java-index,Security,Cryptography...