0

I have 1 package that manages the main JFrame of my application.
This JFrame needs to access an image (which is a resource) of another package.

I was able to get it to work using:

new ImageIcon(getClass().getResource("../"+packageName+"/icon.jpg"));

But this does not work when using a runnable jar (getClass().getResource("../"+packageName+"/icon.jpg")) returns null). Any suggestions?

2
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by majestic0110
0

I know all that already, but it doesn't explain how I can get the image from a different package in the same project...

getClass().getResource(...)

package OtherApp:
icon.jpg


package MainFrame:
MainApp - needs icon.jpg


You would think
getClass().getResource("../OtherApp/icon.jpg") would work.

It does, but not when using a runnable jar.

Edited by TheWhite: n/a

0

Has the directory structure of the packages been modified after the files have been added to a JAR? You will need to modify the

getClass().getResource("../OtherApp/icon.jpg")

statement to reflect this modification. Also, did you read the section regarding URL's in that link I sent you just below

Accessing resources in a JAR.

?

Edited by majestic0110: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.