• 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

Reading from a JAR file

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to load data from a file held in one of the jar files in the ARCHIVE parameter?
Basically, I've got a couple of property files that I'd love the applet to read when it gets initialised.
Can anyone help?
 
Lee Feder
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh I forgot, the applet must be able to run offline too.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lee,
Here is how you would do it :

Where you would replace ClassName with the real name of your class, and image.gif with the real name of the image you are loading ( along with it's path in the JAR file if applicable ). This will work both on and offline.
HTH,
-Nate
 
Lee Feder
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Nate, it works a treat.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , ppl
It is working fine in IE but it is giving error with NS..
Kindly help me out
Regards
Khurram Fakhar
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay... Ummm... could you say what error it is giving in Netscape...
 
Khurram Fakhar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works fine with
URL url1 = ClassName.class.getResource("loginpage_image.jpg");
but on the second line it gives the following error:
line :
panelImage=Toolkit.getDefaultToolkit().getImage(url1);
error :
java.lang.NullPointerException
at sun.awt.SunToolkit.getImageFromHash(Compiled Code)
at sun.awt.SunToolkit.getImage(Compiled Code)
at ClientMain.images(Compiled Code)
at ClientMain.init(Compiled Code)
* at netscape.applet.DerivedAppletFrame$InitAppletEvent.dispatch(Compiled Code)
at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)
at java.awt.EventDispatchThread.run(Compiled Code)
at netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled Code)

but working fine with IE .. ..
isn't it strange ?

regards
Khurram Fakhar
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm... I don't have Netscape here at work to test it out on, but have you tried to replace :


with :


( I assume you are doing this in an Applet... )

Hopefully this works... if not please post again...


-Nate
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, ignore the previous post... I did a search on this and found that Netscape's getResource() method is broken...

Here's some code I found in a JavaWorld article ( http://www.javaworld.com/javaworld/jw-07-1998/jw-07-jar_p.html ) that should help you out...



You should call it in your code like this:


HTH,
-Nate
 
Khurram Fakhar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hay Thanx a million Man
It worked. I studied the whole article .. very well written article .
Thanx once again ..
Regards
Khurram Fakhar
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic