I am trying to write an excel file in a directory that the user will selected with a JFileChooser which is already working well.
My problem is that, when I am passing the path to a 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);
}
}
}
I receive the next exception:
"AWT-EventQueue-0" java.lang.NullPointerException
And the program broke.
I search for many websites and it looks like my code is fine. Any help with be appreciate.