0

I am using NetBeans to create an application and my application running well but when I clean and build this application JButton does not work. It makes me very confused and I have searched it on internet but have found no solution.

This is my source code:

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
   new jogus_l1().setVisible(true);
   dispose();
}

this is the error which I have got from command line :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.ImageIcon.<init>(Unknown Source)
        at final_project_game.jogus_l1.setCards(jogus_l1.java:74)
        at final_project_game.jogus_l1.<init>(jogus_l1.java:44)
        at final_project_game.index.jButton3ActionPerformed(index.java:51)
        at final_project_game.index.access$000(index.java:9)
        at final_project_game.index$1.actionPerformed(index.java:36)
        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.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
        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.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(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)
Tino_Lor
  • 23
  • 3
  • What's the main objective of this button? What does it do? – Taher A. Ghaleb Feb 03 '18 at 03:23
  • 1
    Not enough information. Post [mcve] – c0der Feb 03 '18 at 05:28
  • 1
    Are you running the Jar from Netbeans or from outside Netbeans (e.g. by double clicking an executable Jar)? If the latter, any error output will be hidden from view. To rectify that, run the app, from the command line. If you cannot solve it from seeing the output, post an MCVE as suggested by @c0der. – Andrew Thompson Feb 03 '18 at 07:57
  • BTW `new jogus_l1().setVisible(true); dispose();` See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Feb 03 '18 at 08:02
  • mr. Andrew Thompson..when I am running this jar files in netbeans it is work as well.. but when I running outside netbeans(e.g double clicking an Jar) it does work??..so why it does not work..?? what would I do?? – Tino_Lor Feb 04 '18 at 05:02
  • Tip: Add @c0der (or whoever, **the `@` is important**) to *notify* the person of a new comment. *"..so why it does not work..??"* See [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/q/3988788/418556) & [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/q/218384/418556) – Andrew Thompson Feb 04 '18 at 05:30
  • I have try to run this jar using command line but I get some error.. I have add this errors in my post. You can see it..If possibility please explain this error so I can understand...Thanks – Tino_Lor Feb 04 '18 at 05:31
  • BTW - Application resources will become embedded resources by the time of deployment (or in an executable Jar), so it is wise to start accessing them as if they were, right now. An [tag:embedded-resource] must be accessed by URL rather than file. See the [info. page for embedded resource](http://stackoverflow.com/tags/embedded-resource/info) for how to form the URL. – Andrew Thompson Feb 04 '18 at 05:31
  • Ok..I will try it. If I have any confusing I will comment it later..btw thanks for response.. – Tino_Lor Feb 04 '18 at 05:46
  • 1
    You get a NullPointerException at line 74: "setCards(jogus_l1.java:74)", probably because of an image which was not loaded. We do not know which line is 74, but you do. It will make helping you easier if you put a comment next to the line in the code: `//line 74` – c0der Feb 04 '18 at 06:02
  • Yeah I think you are right..maybe the problem is in image because when I remove the Image the program running well in jar..Do you any sites,url or any tutorial which can explain about import Image in netbeans IDE??? – Tino_Lor Feb 08 '18 at 00:53

0 Answers0