NullPointerException when showing JFileChooser
- by Geo
I show a JFileChooser with this snippet:
public File getDestination() {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int option = chooser.showSaveDialog(null);
if(option == JFileChooser.APPROVE_OPTION) {
return chooser.getSelectedFile().getAbsolutePath();
}
return new File(".");
}
Usually, the first time it's showed, it displays & works correctly. The second time, it will always throw this exception:
Exception in thread "Basic L&F File Loading Thread" java.lang.NullPointerException
at sun.awt.shell.Win32ShellFolder2.pidlsEqual(Unknown Source)
at sun.awt.shell.Win32ShellFolder2.equals(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2.isFileSystemRoot(Unknown Source)
at sun.awt.shell.ShellFolder.isFileSystemRoot(Unknown Source)
at javax.swing.filechooser.FileSystemView.isFileSystemRoot(Unknown Source)
at javax.swing.filechooser.WindowsFileSystemView.isTraversable(Unknown Source)
at javax.swing.JFileChooser.isTraversable(Unknown Source)
at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run0(Unknown Source)
at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run(Unknown Source)
Java -version says:
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)
And the thread I found here says I should downgrade the Java version. Should I follow their advice, or is there something I could have done wrong?