• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

getResource error when starting application in a jar file

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application which I've packaged into a jar file. One of the first statements in my app is


However, when I run my app, I get a null pointer exception from the above line of code. When I run the app from within Eclipse, the app starts fine.

This is my first time creating a jar file and I suspect my error has something to do with that. Can anyone provide clues/suggestions as to what might be wrong?

Thanks.
 
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is because class loading in eclipse works a little differently than elsewise. Try this --

this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath();

 
Steve O Murphy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sai. That solved the problem.

When I print the value of the rootResource to the console I get:
That is indeed the path/name of the jar file.

From there I need to get to the "images" directory in the jar file so I can load images into the app's user interface.

The "images" directory is in the root of the jar file. I'm using the following:

Is that the correct way to get the path to the images directory?

When I try loading an icon, I get an error. Here is what I use:

I get the second exception.
The code for loading the icon works in Eclipse.

Thanks for bearing with me!
Steve
 
Sai Hegde
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are the images bundled within the jar or will they be picked up from the location of your JAR file?
 
Steve O Murphy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The images are in the jar file, in a directory within the jar file called "images"

Thanks.
 
Sai Hegde
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try it this way --


 
reply
    Bookmark Topic Watch Topic
  • New Topic