jar file not working


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)
zolfAsked:
Who is Participating?
 
objectsCommented:
> 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
 
CEHJCommented:
List your jar and make sure everything's there

jar tf yourjar.jar
0
 
objectsCommented:
It is not finding the image
make sure the image path you are using matches the path of the image in your jar
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
zolfAuthor Commented:

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
 
zolfAuthor Commented:


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
 
objectsCommented:
> 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
 
zolfAuthor Commented:

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
 
CEHJCommented:
>>does the jar change the codes in my application???

No. Please post the result of the command i gave you earlier
0
 
zolfAuthor Commented:
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
 
CEHJCommented:
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
 
zolfAuthor Commented:


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
 
zolfAuthor Commented:

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
 
objectsCommented:
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
 
CEHJCommented:
That's looking better but check out my comment above:

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


this is line 12 at Frm_add_edit_dslam.java:12)

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

cehj that is correct
0
 
objectsCommented:
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
 
zolfAuthor Commented:

save.png and SAVE.png  is'nt it the same
0
 
CEHJCommented:
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
 
objectsCommented:
> save.png and SAVE.png  is'nt it the same

no, Java is case sensitive
0
 
CEHJCommented:
>>save.png and SAVE.png  is'nt it the same

No
0
 
zolfAuthor Commented:

thanks very much guys
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.