This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading icon using ImageIO.Read

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Currently, I put my icon for my Frame in my "src" folder, where src is inside of the application folder.
I am using Netbeans.

When this runs inside netbeans, it is fine. But when it is compiled as a jar, I've got null exception thrown by this method as it is running.
I've put the same .png file inside the dist folder. Where am I supposed to put the JFrame folder's icon?
Thanks
Jack
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should go in the root folder in the jar file. That's what it means to use an absolute URL, as you did in that case. Your Netbeans "src" and "dist" folders have nothing to do with anything once you generate the jar, so just forget about them. If they are in the jar, then you have done something wrong while creating it.

And by the way it's less confusing to just use an ordinary absolute URL, like this:
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
I am still experiencing some difficulties, I use the directory as you informed me.
I put the bokss.png file in the same folder with the manifest.mf and build.xml.
I even can't execute the application in netbeans.
Thanks
Jack
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually Paul, the original resource was relative to the class file itself (the ./ works in resources just like in file systems). And that's where the icon should be - inside the JAR file. Don't assume it automatically gets packed. Check if it is, and if it isn't make sure it is.

The location inside the JAR file also matters. If the resource is relative (like ./bokss.png) then the icon must be located relative to the class file. If it's absolute (like /bokss.png) then it must be located to the root of the JAR file. Unlike the manifest file which must be placed inside the META-INF folder inside the JAR file.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Actually Paul, the original resource was relative to the class file itself (the ./ works in resources just like in file systems).


That's why I used the word "confusing" in my response. When "./abc" is the same thing as "abc" then you should not use the more complicated form.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Rob Spoor wrote:Actually Paul, the original resource was relative to the class file itself (the ./ works in resources just like in file systems).


That's why I used the word "confusing" in my response. When "./abc" is the same thing as "abc" then you should not use the more complicated form.


2 points I would like to raise
I can do one of the options either
1) add the bokss.png file to the jar file
2) modify the manifest.mf



I prefer the second method to the first. How do I modify this file to include the png file?
Thanks
Jack
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack Luk wrote:
Paul Clapham wrote:
Rob Spoor wrote:Actually Paul, the original resource was relative to the class file itself (the ./ works in resources just like in file systems).


That's why I used the word "confusing" in my response. When "./abc" is the same thing as "abc" then you should not use the more complicated form.


2 points I would like to raise
I can do one of the options either
1) add the bokss.png file to the jar file
2) modify the manifest.mf



I prefer the second method to the first. How do I modify this file to include the png file?
Thanks
Jack


I've solved it. Sorry, but I've lost the link that I originally wanted to share with you. Just google something like "manifest.mf resource png"
But I can't get to it.
Thanks
Jack
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic