• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Couldn't find file "C:\...\Images\"

Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am not sure if I am in the right spot or not. I am experimenting with modifying the sample code in the Java tutorials, specifically the RadioButtonDemo. Instead of their pictures of various critters, I thought I would comic strips saved in an images folder.

Here is where the folder (with the comic strips) is: C:\Documents and Settings\jenr\Images

When I compile and run it, here is the error I get:
Couldn't find file: C:\Documents and Settings\jenr\Images\jefferson.gif

I am thinking I am misunderstanding what this chunk of code is supposed to do:
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = Main.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;

Any help would be greatly appreciated. I am trying to tune up my skills in preparation for starting the process of getting certified in JAVA for my employer.

Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The 'getResource' method has the ClassLoader look for the resource on the class path. If your 'Documents and Settings' folder is not be on the class path you can try building a URL with something like this:

The swing tutorial has a page on how to use icons that contains a lot of information about things like accessing and loading images, file structure, jar files, and use of the 'getResource' method.
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic