Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do I always get this exception?
    primarykey
    data
    text
    <p>I developed an app with a GUI, with buttons, relative actionListeners, and exceptions. Today I had this problem. In an <code>actionEvent</code> relative to a button of my GUI, I inserted this code, with some <code>JOptionPane.showInputDialog</code>:</p> <pre><code>public void actionPerformed(ActionEvent ae){ if(ae.getSource()==b1){ try{//FIRST `JOptionPane.showInputDialog` int load = Integer.parseInt(JOptionPane.showInputDialog(null,"Insert current load value: ")); auto.setCurrentLoad(load); //other `JOptionPane.showInputDialog` int choiceDep = Integer.parseInt(JOptionPane.showInputDialog(null, "Does the truck transport perishable goods? 1: YES 2: NO")); if(choiceDep==1) { //here we have to insert expiration date int day = Integer.parseInt(JOptionPane.showInputDialog(null,"Insert value")); int month = Integer.parseInt(JOptionPane.showInputDialog(null,"Insert value")); int year = Integer.parseInt(JOptionPane.showInputDialog(null,"Insert value")); auto.setPerishable(day,month,year); } else if(choiceDep==2) auto.setNotPerishable(); String choiceAv = JOptionPane.showInputDialog(null, "Available Truck? Yes or no?"); if(choiceAv.equals("Yes")) auto.setAvailable(); else auto.setNotAvailable(); } //the exception catch (Exception e) { System.out.println("Exception!");} } </code></pre> <p>Where <code>setAvailable, setNotAvailable,setPerishable,setCurrentLoad</code> are methods of the external class, with reference <code>auto</code>.</p> <p>When I execute this code, it appears the GUI, then I click on button <code>b1</code>. It appears the first <code>JOptionPane.showInputDialog</code>, to insert a value stored in a <code>int load</code>.</p> <p>I entered a value, but no other <code>JOptionPane.showInputDialog</code> appeared (but there are other input dialog) and I got the exception in the command-line. I noticed that the value inserted in the <code>JOptionPane.showInputDialog</code> is never passed to the line <code>auto.setCurrentLoad(load);</code>. </p> <p>Why does it happen? Never seen this error before. Why do I always get the exception immediately after the first <code>JOptionPane.showInputDialog</code> Maybe the JVM doesn't accept many of this <code>JOptionPane.showInputDialog</code> in the same statement/method? Or maybe(as I think) is a programming error of mine?</p> <p>Thanks for your help. Cheers.</p> <p>EDIT: I forgot to insert the exception I got in the command-line: </p> <pre><code>java.lang.NullPointerException at AutoCom.actionPerformed(AutoCom.java:50) 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 So 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.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) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload