开发者

NullPointerException when showing JFileChooser

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 开发者_StackOverflow社区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?


This is fixed in build 1.6u21

See here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6940843


That really looks like it's a version problem / regression. So the answer would hence be: follow their advice, you haven't done anything wrong ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜