Action sur un combobox et Exception in thread "AWT-EventQueue-0" java.lang.NullP

radmanolf Messages postés 8 Date d'inscription vendredi 4 juin 2004 Statut Membre Dernière intervention 18 juin 2008 - 18 juin 2008 à 04:16
cs_jojolemariole Messages postés 519 Date d'inscription mercredi 21 mars 2007 Statut Membre Dernière intervention 19 décembre 2016 - 18 juin 2008 à 10:53
salut

Bon moi j ai un gros probleme et j ai vraiment besoin de votre aide
donc j ai deux combobox dans la premiere j ai des services et dans la deuxieme j ai les debits utilisés pour ces services
il faut que quand je fixe le service "voice" dans le 1er combobox le 2eme combobox affiche seulement le débit "12.2" et devient disabled . Pour ça j ai écris un code qui a fonctionné:





private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        int modifiers;
         if (evt instanceof ActionEvent) {
              modifiers = ((ActionEvent)evt).getModifiers();
              long modsLong = modifiers & ActionEvent.MOUSE_EVENT_MASK;
              if (modsLong == MouseEvent.BUTTON1_MASK) {
               //   System.out.println(this.jComboBox1.getItemAt(this.jComboBox1.getSelectedIndex()).toString());
                  if(this.jComboBox1.getItemAt(this.jComboBox1.getSelectedIndex()).toString().equalsIgnoreCase("voice")){
                  this.jComboBox2.removeAllItems();
                  this.jComboBox2.addItem("12.2");
                  this.jComboBox2.setEnabled(false);
                  }else
                      GetServicesRate();
                 

              }
         }


mais seulement au début maintenant quand je sélectionne voice dans le combobox1 il n'affiche plus rien dans le combobox2 et l affichage devient bizare et quand j essaye de selectionner un autre service l affichage ne change pas et le combobox2 reste aussi vide.

et l'exception suivante apparait:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:991)
        at java.lang.Double.parseDouble(Double.java:510)
        at BudgetLink_View.TestingForm.jComboBox2ActionPerformed(TestingForm.java:648)
        at BudgetLink_View.TestingForm.access$100(TestingForm.java:22)
        at BudgetLink_View.TestingForm$2.actionPerformed(TestingForm.java:143)
        at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1242)
        at javax.swing.JComboBox.contentsChanged(JComboBox.java:1313)
        at javax.swing.JComboBox.intervalRemoved(JComboBox.java:1333)
        at javax.swing.AbstractListModel.fireIntervalRemoved(AbstractListModel.java:161)
        at javax.swing.DefaultComboBoxModel.removeAllElements(DefaultComboBoxModel.java:169)
        at javax.swing.JComboBox.removeAllItems(JComboBox.java:753)
        at BudgetLink_View.TestingForm.GetServicesRate(TestingForm.java:710)
        at BudgetLink_View.TestingForm.jComboBox1ActionPerformed(TestingForm.java:607)
        at BudgetLink_View.TestingForm.access$000(TestingForm.java:22)
        at BudgetLink_View.TestingForm$1.actionPerformed(TestingForm.java:134)
        at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1242)
        at javax.swing.JComboBox.setSelectedItem(JComboBox.java:569)
        at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:605)
        at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:814)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
        at java.awt.Component.processMouseEvent(Component.java:6038)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
        at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:480)
        at java.awt.Component.processEvent(Component.java:5803)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4410)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4240)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
        at java.awt.Container.dispatchEventImpl(Container.java:2102)
        at java.awt.Window.dispatchEventImpl(Window.java:2429)
        at java.awt.Component.dispatchEvent(Component.java:4240)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)




Merci pour votre aide c tres urgent!!!   

1 réponse

cs_jojolemariole Messages postés 519 Date d'inscription mercredi 21 mars 2007 Statut Membre Dernière intervention 19 décembre 2016 25
18 juin 2008 à 10:53
Salut,

Merci pour la stack trace :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:991)
        at java.lang.Double.parseDouble(Double.java:510)
        at BudgetLink_View.TestingForm.jComboBox2ActionPerformed(TestingForm.java:648)
        at BudgetLink_View.TestingForm.access$100(TestingForm.java:22)
        at BudgetLink_View.TestingForm$2.actionPerformed(TestingForm.java:143)
        at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1242)
        at javax.swing.JComboBox.contentsChanged(JComboBox.java:1313)
        at javax.swing.JComboBox.intervalRemoved(JComboBox.java:1333)
        at javax.swing.AbstractListModel.fireIntervalRemoved(AbstractListModel.java:161)
        at javax.swing.DefaultComboBoxModel.removeAllElements(DefaultComboBoxModel.java:169)
        at javax.swing.JComboBox.removeAllItems(JComboBox.java:753)
        at BudgetLink_View.TestingForm.GetServicesRate(TestingForm.java:710)
        at BudgetLink_View.TestingForm.jComboBox1ActionPerformed(TestingForm.java:607)
        at BudgetLink_View.TestingForm.access$000(TestingForm.java:22)
        at BudgetLink_View.TestingForm$1.actionPerformed(TestingForm.java:134)
        at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1242)
        at javax.swing.JComboBox.setSelectedItem(JComboBox.java:569)
        at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:605)
        at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:814)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
        at java.awt.Component.processMouseEvent(Component.java:6038)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
        at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:480)
        at java.awt.Component.processEvent(Component.java:5803)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4410)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4240)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
        at java.awt.Container.dispatchEventImpl(Container.java:2102)
        at java.awt.Window.dispatchEventImpl(Window.java:2429)
        at java.awt.Component.dispatchEvent(Component.java:4240)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Cette pile retrace tous les appels de fonction, le dernier appel de fonction exécuté étant situé en haut de la pile, (c'est le principe d'une pile).

Je t'ai mis en violet, ce qui se passait dans les librairies Java, et en bleu ce qui se passe dans tes librairies.

D'abord on voit que tu déclenches un évènement, sans doute quand tu sélectionnes un item dans ta première comboBox. Tu passes donc par jComboBox1ActionPerformed,
ensuite tu appelles GetServicesRate. Ce qui signifie, d'après ton code que tu n'as pas sélectionné "voice". La méthode GetServicesRate appelle removeAllElements sur ton deuxième comboBox apparemment.  Et suite à ce vidage de ton deuxième combobox, on arrive dans l'écouteur : jComboBox2ActionPerformed, lequel a appelé parseDouble sur une chaîne de caractères.  Dis-nous juste quelle chaîne de caractère tu vas lire dans jComboBox2ActionPerformedet on pourra te dire ce qui cloche.
0
Rejoignez-nous