• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't read icon from resource

 
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can read icon from specified directory:

but :
- I want the icons will be in project directory
- project directory can be changed
- if it is possible also read from .jar in future

- not works, return null
not works
not works

My simple program consists of two files:



I attach also folder16.png
folder16.png
[Thumbnail for folder16.png]
 
Andrzej Borucki
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My .classpath file:

 
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code using an ImageIcon is loading folder16.png, the code using getResource is attempting to load folder.png. Is this a typo in the code or in the post?

Where is the folder containing the image relative to your source code?
 
Andrzej Borucki
Ranch Hand
Posts: 101
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right now is OK. I use
Problem was that image must be in .class folder, not in .java folder. But happily when compile with Eclipse it is copy from src\ to bin\
I placed in d:\code\junace.git\demo\src\net\sf\junace\demo\folder16.png and getResource call without paths.
Prerequisites to be succeeded
- after placing to src\package directory refresh (F5) project
- if still error, call Project->Clean
- Build and Run
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to hear it is resolved and thank you for updating the thread with how you solved it.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A minor nitpick

From the API docs for Class#getResourceAsStream

...This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader, the method delegates to ClassLoader.getSystemResourceAsStream(java.lang.String)....



As you can see, you really don't need to explicitly use the class loader !

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic