Problème avec un ListSelectionListener
Bonsoir,
Lors de l'initialisation de ma classe (un JDialog contenant une JList), j'ai une Exception :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at gui.dialog.NewFileWizard2.<init>(NewFileWizard2.java:246)
at action.Dialog.showNewFileWizard(Dialog.java:40)
at gui.dialog.NewFileWizard1$4.actionPerformed(NewFileWizard1.java:240)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110) |
J'ai découvert que cela veneai de mon ListSelectionListener dont voici le code.
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| //Si on selectionne un objet dans la liste
lstActivite.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
// Recupere la valeur de l'objet et la convertit en chaine'
String value = String.valueOf(lstActivite.getSelectedValue());
// place la valeur dans le champs valeur
fldValeur.setText(value);
}
}); |
J'utlise un DefaultListModel, et je pense que ça vient de là car quand j'utilise un AbstractListModel tout se passe sans problème.
Hors, j'ai d'un DefaultListModel afin de pouvoir ajouter des éléments à ma JList.
Merci de bien vouloir m'éclairer :arf: