• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't read icon from resource

 
Andrzej Borucki
Ranch Hand
Posts: 83
1
  • Mark post as helpful
  • send pies
  • 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: 83
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My .classpath file:

 
Tony Docherty
Bartender
Posts: 2988
59
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 83
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 2988
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to hear it is resolved and thank you for updating the thread with how you solved it.
 
Maneesh Godbole
Saloon Keeper
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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 !

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic