[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

jar file not working

Posted on 2006-05-30
23
Medium Priority
?
296 Views
Last Modified: 2010-08-05

hello there,

i have a jar file which contains all the required resources to start my application.when i run the jar file the application starts,but some of its features are not working.but before jaring the application i tested with my java IDE eclipse and it works perfect.what could be the problem.the error i get is

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.ImageIcon.<init>(Unknown Source)
        at src.com.victa.PictMenuFrameDemo.loadImage(PictMenuFrameDemo.java:174)

        at src.com.victa.PictMenuFrameDemo.initImages(PictMenuFrameDemo.java:180
)
        at src.com.victa.PictMenuFrameDemo.createMenuBar(PictMenuFrameDemo.java:
88)
        at src.com.victa.PictMenuFrameDemo.<init>(PictMenuFrameDemo.java:69)
        at src.com.victa.PictMenuFrameDemo.createAndShowGUI(PictMenuFrameDemo.ja
va:354)
        at src.com.victa.PictMenuFrameDemo.access$0(PictMenuFrameDemo.java:350)
        at src.com.victa.PictMenuFrameDemo$2.run(PictMenuFrameDemo.java:395)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
0
Comment
Question by:zolf
  • 10
  • 7
  • 6
23 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16795957
List your jar and make sure everything's there

jar tf yourjar.jar
0
 
LVL 92

Expert Comment

by:objects
ID: 16795971
It is not finding the image
make sure the image path you are using matches the path of the image in your jar
0
 

Author Comment

by:zolf
ID: 16796022

i have kept it simple this time with out using build.xml

i have all my jars,images folder,db.properties in C:\Java\test3

images
db.properties
mysql-connector-java-3.0.15-ga-bin.jar
newdslam.jar
ojdbc14.jar

when i try to run newdslam.jar i get the above error.

in my code i have changed all my

protected ImageIcon loadImage(String fname)
      {
            //return new ImageIcon(Toolkit.getDefaultToolkit().createImage(fname));
            return new ImageIcon(getClass().getResource(fname));
      }
      
      // Init images for menu items
      protected void initImages()
      {
            menuOneIm = loadImage("/images/arrowIcon.png");
            
            menuTwoIm = loadImage("/images/newIcon.png");      
            
            menuTreeIm = loadImage("/images/printIcon.png");
            
            smenuOneIm = loadImage("/images/logo.png");
                  
            smenuTwoIm = loadImage("/images/def.png");
            
      }
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:zolf
ID: 16796031


the application is working perfect in eclipse but when i jar the application i get this error????????????

does the jar change the codes in my application???
0
 
LVL 92

Expert Comment

by:objects
ID: 16796039
> i have all my jars,images folder,db.properties in C:\Java\test3

they need to be in your jar (in an images directory), is that the case?
0
 

Author Comment

by:zolf
ID: 16796058

objects,i did not understand what you meant.

i have a images folder in C:\Java\test3 where the images folder has icons in it.

this is my manifest file :

Manifest-Version: 1.0
Main-Class: src.com.victa.PictMenuFrameDemo
Class-Path: mysql-connector-java-3.0.15-ga-bin.jar ojdbc14.jar


do i need to add images folder into it ?
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 440 total points
ID: 16796061
>>does the jar change the codes in my application???

No. Please post the result of the command i gave you earlier
0
 

Author Comment

by:zolf
ID: 16796075
C:\Java\test3>jar -tf newdslam.jar
META-INF/MANIFEST.MF
src/com/victa/Frm_add_edit_dslamBrand$1.class
src/com/victa/Frm_add_edit_dslamBrand.class
src/com/victa/PictMenu.class
src/com/victa/SimplePictMenu$1.class
src/com/victa/SimplePictMenu.class
src/com/victa/Frm_add_edit_linecardBrand$1.class
src/com/victa/Frm_add_edit_linecardBrand.class
src/com/victa/Frm_add_edit_co$1.class
src/com/victa/Frm_add_edit_co.class
src/com/victa/TreeTableInternalFrame$1.class
src/com/victa/TreeTableInternalFrame$10.class
src/com/victa/TreeTableInternalFrame$11.class
src/com/victa/TreeTableInternalFrame$12.class
src/com/victa/TreeTableInternalFrame$13.class
src/com/victa/TreeTableInternalFrame$14.class
src/com/victa/TreeTableInternalFrame$15.class
src/com/victa/TreeTableInternalFrame$2.class
src/com/victa/TreeTableInternalFrame$3.class
src/com/victa/TreeTableInternalFrame$4.class
src/com/victa/TreeTableInternalFrame$5.class
src/com/victa/TreeTableInternalFrame$6.class
src/com/victa/TreeTableInternalFrame$7.class
src/com/victa/TreeTableInternalFrame$8.class
src/com/victa/TreeTableInternalFrame$9.class
src/com/victa/TreeTableInternalFrame$CityEngNameComparator.class
src/com/victa/TreeTableInternalFrame$ForeignKeyComparator.class
src/com/victa/TreeTableInternalFrame$MyRenderer.class
src/com/victa/TreeTableInternalFrame$PrimryKeyComparator.class
src/com/victa/TreeTableInternalFrame.class
src/com/victa/CoRow.class
src/com/victa/Frm_add_edit_linecard$1.class
src/com/victa/Frm_add_edit_linecard.class
src/com/victa/BaseRow.class
src/com/victa/PictMenuFrameDemo$1.class
src/com/victa/PictMenuFrameDemo$2.class
src/com/victa/PictMenuFrameDemo.class
src/com/victa/clsPublicMethods.class
src/com/victa/PictButton.class
src/com/victa/LinecardRow.class
src/com/victa/TestStruct.class
src/com/victa/Frm_add_edit_city$1.class
src/com/victa/Frm_add_edit_city.class
src/com/victa/mdlFunctions.class
src/com/victa/PictureFrame$1.class
src/com/victa/PictureFrame$2.class
src/com/victa/PictureFrame.class
src/com/victa/ServerImageFrame$1.class
src/com/victa/ServerImageFrame$2.class
src/com/victa/ServerImageFrame$PictPanel.class
src/com/victa/ServerImageFrame.class
src/com/victa/CityRow.class
src/com/victa/Frm_add_edit_dslam$1.class
src/com/victa/Frm_add_edit_dslam.class
src/com/victa/DslamRow.class
0
 
LVL 92

Accepted Solution

by:
objects earned 560 total points
ID: 16796084
> objects,i did not understand what you meant.
> i have a images folder in C:\Java\test3 where the images folder has icons in it.

I meant they need to be in your jar, as u are running from the jar it needs to contains any resources required.
Your jar does not contain the image or your properties.
Check your jars build script.

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16796091
That jar is wrong in probably at least two respects:

a. there's no /images entry
b. the entry beginning src should probably begin com
0
 

Author Comment

by:zolf
ID: 16796103


ok i did that and it worked.but now it gives me another error in my apllication when i clcik on a button

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.ImageIcon.<init>(Unknown Source)
        at src.com.victa.Frm_add_edit_dslam.<init>(Frm_add_edit_dslam.java:12)
        at src.com.victa.TreeTableInternalFrame$10.actionPerformed(TreeTableInte
rnalFrame.java:1165)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.AbstractButton.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown
Source)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
0
 

Author Comment

by:zolf
ID: 16796107

this is my new jar

C:\Java\test3>jar -tf newdslam.jar
META-INF/MANIFEST.MF
src/com/victa/Frm_add_edit_dslamBrand$1.class
src/com/victa/Frm_add_edit_dslamBrand.class
src/com/victa/PictMenu.class
src/com/victa/SimplePictMenu$1.class
src/com/victa/SimplePictMenu.class
src/com/victa/Frm_add_edit_linecardBrand$1.class
src/com/victa/Frm_add_edit_linecardBrand.class
src/com/victa/Frm_add_edit_co$1.class
src/com/victa/Frm_add_edit_co.class
src/com/victa/TreeTableInternalFrame$1.class
src/com/victa/TreeTableInternalFrame$10.class
src/com/victa/TreeTableInternalFrame$11.class
src/com/victa/TreeTableInternalFrame$12.class
src/com/victa/TreeTableInternalFrame$13.class
src/com/victa/TreeTableInternalFrame$14.class
src/com/victa/TreeTableInternalFrame$15.class
src/com/victa/TreeTableInternalFrame$2.class
src/com/victa/TreeTableInternalFrame$3.class
src/com/victa/TreeTableInternalFrame$4.class
src/com/victa/TreeTableInternalFrame$5.class
src/com/victa/TreeTableInternalFrame$6.class
src/com/victa/TreeTableInternalFrame$7.class
src/com/victa/TreeTableInternalFrame$8.class
src/com/victa/TreeTableInternalFrame$9.class
src/com/victa/TreeTableInternalFrame$CityEngNameComparator.class
src/com/victa/TreeTableInternalFrame$ForeignKeyComparator.class
src/com/victa/TreeTableInternalFrame$MyRenderer.class
src/com/victa/TreeTableInternalFrame$PrimryKeyComparator.class
src/com/victa/TreeTableInternalFrame.class
src/com/victa/CoRow.class
src/com/victa/Frm_add_edit_linecard$1.class
src/com/victa/Frm_add_edit_linecard.class
src/com/victa/BaseRow.class
src/com/victa/PictMenuFrameDemo$1.class
src/com/victa/PictMenuFrameDemo$2.class
src/com/victa/PictMenuFrameDemo.class
src/com/victa/clsPublicMethods.class
src/com/victa/PictButton.class
src/com/victa/LinecardRow.class
src/com/victa/TestStruct.class
src/com/victa/Frm_add_edit_city$1.class
src/com/victa/Frm_add_edit_city.class
src/com/victa/mdlFunctions.class
src/com/victa/PictureFrame$1.class
src/com/victa/PictureFrame$2.class
src/com/victa/PictureFrame.class
src/com/victa/ServerImageFrame$1.class
src/com/victa/ServerImageFrame$2.class
src/com/victa/ServerImageFrame$PictPanel.class
src/com/victa/ServerImageFrame.class
src/com/victa/CityRow.class
src/com/victa/Frm_add_edit_dslam$1.class
src/com/victa/Frm_add_edit_dslam.class
src/com/victa/DslamRow.class
images/7224.jpg
images/CANCEL.PNG
images/RESET.PNG
images/SAVE.PNG
images/Thumbs.db
images/arrowIcon.png
images/bNew.png
images/cardIcon.png
images/cityIcon.png
images/citynode.png
images/coIcon.png
images/def.png
images/dslamIcon.png
images/logo.png
images/newIcon.png
images/printIcon.png
images/testIcon.png
db.properties
0
 
LVL 92

Expert Comment

by:objects
ID: 16796109
check line 12 in Frm_add_edit_dslam.java
it appears to be loading an image path that does not exist in your jar
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16796114
That's looking better but check out my comment above:

>>b. the entry beginning src should probably begin com
0
 

Author Comment

by:zolf
ID: 16796118


this is line 12 at Frm_add_edit_dslam.java:12)

JButton JBUpdate = new JButton(new ImageIcon(getClass().getResource("/images/save.png")));
0
 

Author Comment

by:zolf
ID: 16796122

cehj that is correct
0
 
LVL 92

Expert Comment

by:objects
ID: 16796128
JButton JBUpdate = new JButton(new ImageIcon(getClass().getResource("/images/sSAVE.PNG")));

check your other bottons as well, and make them upper case
or change the case of the filenames
0
 

Author Comment

by:zolf
ID: 16796130

save.png and SAVE.png  is'nt it the same
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16796133
I take it that the relevant source files start

package com.victa;

? If so, you need to create the jar with its root as com, not src
0
 
LVL 92

Expert Comment

by:objects
ID: 16796138
> save.png and SAVE.png  is'nt it the same

no, Java is case sensitive
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16796139
>>save.png and SAVE.png  is'nt it the same

No
0
 

Author Comment

by:zolf
ID: 16796195

thanks very much guys
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16796201
:-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question