I'm using an ActionListener to update a JList whenever an item is selected.
jComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox) e.getSource();
updateLocalFileList( cb.getSelectedItem().toString() );
}
});
It is calling this method for the UI.
public void updateLocalFileList( String path ){
DefaultListModel model = new DefaultListModel();
for (String str : LocalFileSystem.getFileListFromDirectory( path )) {
model.addElement( str );
}
getJList().setModel(model);
}
If getFileListFromDirectory() gives a NullPointerException, say when the letter of an empty dvd drive is selected, it seems to prevent the ActionListener from working as intended.
I'm not sure what's happening exactly but I suspect that passing a null value to the model is causing this issue.
Any ideas?
Edit
Here is the stacktrace as requested. As you can see, the method is obviously triggering a NullPointerException on inacessible drives. I don't precisely why it prevents the JList updating though since the rest of the application works fine.
java.lang.NullPointerException
at mine.View.updateLocalFileList(View.java:274)
at mine.View$1.actionPerformed(View.java:262)
at javax.swing.JComboBox.fireActionEvent(Unknown Source)
at javax.swing.JComboBox.setSelectedItem(Unknown Source)
at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$1.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)