为什么选择jFileChosser.getSelectedFile()。getAbsolutePath();我的项目没有工作?

时间:2017-06-25 17:00:58

标签: java netbeans jfilechooser

我正在尝试在一个目录中编写一个excel文件,用户将使用一个已经运行良好的JFileChooser选择该目录。

我的问题是,当我将路径传递给String时:

private void JFileChooserExcActionPerformed(java.awt.event.ActionEvent evt) {                                                
    JFileChooserExc.setCurrentDirectory(new java.io.File("."));
    JFileChooserExc.setFileSelectionMode(JFileChooserExc.DIRECTORIES_ONLY);
    JFileChooserExc.setAcceptAllFileFilterUsed(false);

    if (JFileChooserExc.showOpenDialog(this) == JFileChooserExc.APPROVE_OPTION) {
        try {
            String path = JFileChooserExc.getSelectedFile().getAbsolutePath(); //Here is the problem
            Rank(path);
        } catch (IOException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

我收到了下一个例外:

  

“AWT-EventQueue-0”java.lang.NullPointerException

程序破了。

我搜索了很多网站,看起来我的代码很好。任何帮助都要欣赏。

0 个答案:

没有答案
相关问题