項目が選択されるたびに ActionListener を使用して JList を更新しています。
jComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox) e.getSource();
updateLocalFileList( cb.getSelectedItem().toString() );
}
});
UI に対してこのメソッドを呼び出しています。
public void updateLocalFileList( String path ){
DefaultListModel model = new DefaultListModel();
for (String str : LocalFileSystem.getFileListFromDirectory( path )) {
model.addElement( str );
}
getJList().setModel(model);
}
getFileListFromDirectory() が NullPointerException を返す場合、たとえば、空の DVD ドライブの文字が選択された場合、ActionListener が意図したとおりに機能しないようです。
何が起こっているのか正確にはわかりませんが、null 値をモデルに渡すことがこの問題を引き起こしていると思われます。
何か案は?
編集
要求されたスタックトレースは次のとおりです。ご覧のとおり、このメソッドは明らかに、アクセスできないドライブで NullPointerException をトリガーしています。アプリケーションの残りの部分は正常に動作するため、JList の更新が妨げられる理由は正確にはわかりません。
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)