Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2004, 11:36 AM
Authorized User
 
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default Jar Resource Access

Hello, all

I'm trying to retrieve an image from within my jar. I have looked at several posts of people who have accomplished this. I think the issue I may be having is specific to the class that uses the image, which belongs to (in this test case) the packagetest package.

This is the main class in the jar:

public class ResourceLoadTest extends JFrame{
    public ResourceLoadTest() {
        setSize(100,100);
        getContentPane().add( new packagetest.ResourcePanelTest());
        setVisible(true);
        setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
    }

    public static void main ( String args[] ){
        ResourceLoadTest r = new ResourceLoadTest();
    }
}


And this is the class in the packagetest package

public class ResourcePanelTest extends JPanel {
    ImageIcon img;
    public ResourcePanelTest() {
         img = new ImageIcon(
            getClass().getResource("images"+java.io.File.separ ator+"mixerIcon.gif")
        );
    }
    public void paint( Graphics g ){
        g.drawImage( img.getImage(), 10, 10, img.getImageObserver());
    }

}

mixerIcon.gif is located in the "packagetest/images" directory, and my app works fine when running normally (not in the jar), but I get a nullpointerexception on the getClass().getResource(...) line when running from within the jar.

I also should point out that when packaging the jar, I'm using the following command

jar cvf ResourceLoadTest .

Thanks for your help :-D

thanks
__________________
thanks
 
Old December 6th, 2004, 01:57 PM
Authorized User
 
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

I resolved this using a heading "/" to indicate an absolute path. Thx for your help :-D

thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
JAR file sugarpalm157 Pro Java 1 August 23rd, 2007 08:27 AM
tools.jar reza_ahmadi Java Espanol 0 December 26th, 2006 07:11 AM
Need ldapfilt.jar and ldapjdk.jar minhpx J2EE 0 June 14th, 2005 10:27 PM
where is wml.jar mask95 All Other Wrox Books 1 August 19th, 2004 09:17 PM
Servlet.jar rockmovinman Apache Tomcat 2 January 17th, 2004 03:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.