• Post Reply Bookmark Topic Watch Topic
  • New Topic

getResource error when starting application in a jar file  RSS feed

 
Steve O Murphy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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.
 
Sai Hegde
security forum advocate
Ranch Hand
Posts: 216
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • 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
  • 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
Ranch Hand
Posts: 216
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • 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
  • 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
Ranch Hand
Posts: 216
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it this way --


 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!