GImage can't find my image

2.5k Views Asked by At

I was trying the acm library and when I tried to use the GImage it can't find my image. I tried putting it everywhere and still it can't find it. Where does GImage look for an image(please be specific) thank you

2

There are 2 best solutions below

0
On

According to the docs. it specifically consists of the following steps:

  1. Check to see if an image with that name has already been defined. If so, return that image.
  2. Check to see if there is a resource available with that name whose contents can be read as an Image. If so, read the image from the resource file.
  3. Load the image from a file with the specified name, relative to the application directory or the applet code base.
0
On

I was also having the same problem. I used the full-path and it worked, e.g.:

GImage img = new GImage("/Users/abc/java/programming/abc.jpg");
add(img);

Also, I just noticed that if you are using Eclipse, you can keep the image inside bin sub-directory and then you can use filename:

GImage img = new GImage("abc.jpg");
add(img);

For the above to work, your image should be at: /Users/abc/java/programming/bin/abc.jpg"