aspose file tools*
The moose likes I/O and Streams and the fly likes Can't read icon from resource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Can Watch "Can New topic
Author

Can't read icon from resource

Andrzej Borucki
Ranch Hand

Joined: Aug 24, 2013
Posts: 50
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]

Andrzej Borucki
Ranch Hand

Joined: Aug 24, 2013
Posts: 50
My .classpath file:

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2405
    
  50
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

Joined: Aug 24, 2013
Posts: 50
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

Joined: Aug 07, 2007
Posts: 2405
    
  50
Glad to hear it is resolved and thank you for updating the thread with how you solved it.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

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 !


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't read icon from resource