• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

image not load in jar

 
Greenhorn
Posts: 2
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,

i'm trying to load image in my project. i'm using netbeans and while project is run from netbeans everything is working fine. after packing project to jar file when run there is no image, just a background and image loads null. can somebody please help me to fix this code? i have tried to load image many different ways but still the same. here is the code:

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the image is packed in the JAR file, then it doesn't exist as a file itself, so you can't really use the methods you do when you run an unpacked version of the application. What you need is to find the Path of the image file as it sits inside the JAR. You normally do this through the ClassLoader. Let's say for example that your JAR file is packed like this:

Jabacina.jar!/ <- root of the jar file
Jabacina.jar!/images/image.png <- image of interest
Jabacina.jar!/jabacina/jabacina.class <- class file in package
Jabacina.jar!/META-INF/MANIFEST.MF <- Manifest file

Then you could do something like
 
Gospodin Dzon
Greenhorn
Posts: 2
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you, my friend. it works now. i have tried using ClassLoader but it seems i havent used it right way.
 
Everybody! Do the Funky Monkey! Like this tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic