NullPointerException
每次打开文件浏览器时我都会得到一个,然后在不选择文件的情况下关闭它。
@Override
public void actionPerformed(ActionEvent e) {
if(!(dndfolder.exists())) {
new File(homefolder + "DND").mkdir();
}
browse = new JFileChooser(homefolder+"DND");
returnVal = browse.showOpenDialog(loadchar);
browse.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if(browse.getSelectedFile().exists()) {
sheet = browse.getSelectedFile();
}
if(sheet.exists() && sheet.getName().endsWith(".txt")) {
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().edit(sheet);
} catch (IOException ex) {
Logger.getLogger(panel.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
error = "*I don't really know what to put here";
repaint();
}
} else {
error = "*File type not supported";
repaint();
}
}
我可以打开文本文件,但当所选项目不存在时它会失败。我试图围绕它编写代码,但我无法让它工作。有任何想法吗?