acm.util.ErrorException: Cannot find image named
I am using Eclipse Galileo. I have a class that should display a deck of cards face down but the image for the card is not found at runtime. I first placed the image inside a folder named "images" inside the project folder. Then I tried placing the image in the same package as the classes but still no luck. The error messages are the same, image not found. I even tried to import the images folder but eclipse recognises the folder and image within the hierarchy of the project and will not allow the import. My question is if it is seen by Eclipse during save/compile, why is it not seen at runtime? What am I missing? I am thinking maybe I have to specify a path as part of the file name, or maybe there is a default location java will seek images. Or ...
If I just use a filled rectangle in place of the image, everything runs fine. By the way, I am toying with the acm package, because I am new to java, and it was introduced to me as "the way to do it". I am seeing its not all it is cracked up to be. I plan to start using java.awt.Image soon. Perhaps now.
Re: acm.util.ErrorException: Cannot find image named
Please post how you are trying to access the images. If you call getResource, the path specified must be relative to the package. So if you package an image into a jar at the root location (not in a package), the you call
Code :
getResource("/myimage.jpg");
if the are in a folder called images, then
Code :
getResource("/images/myimage.jpg");
Note the first slash, indicating the root path of the jar.
Re: acm.util.ErrorException: Cannot find image named
Quote:
Originally Posted by
copeg
Please post how you are trying to access the images...
acm package's GImage as follows:
Code Java:
GImage deck = new GImage("CARD_DECK_BASIC.jpg");
I am learning more and more about awt's Image class and it seems a better way to go. Perhaps for now I should step back and think. Any suggestions on a way to handle this?
I am trying to display this image on the back of a deck of cards. The jpg is smaller than the display size so it will need the scale method. As well as getting the location and other useful methods I find in awt. I guess I am wondering if there is a better way to handle a single image multiple times than the Image class.