hi can anyone tell me why the netbeans ide generates a null pointer exception.
here my code.
for class CustomFileFilter
import java.io.File;
public class CustomFileFilter extends javax.swing.filechooser.FileFilter {
private String extension;
private String description;
public void setDescription(String description) {
this.description = description;
}
public void setExtension(String extension) {
this.extension = extension;
}
public String getExtension() {
return extension;
}
@Override
public boolean accept(File f) {
return f.isDirectory() || f.getAbsolutePath().endsWith(extension);
}
@Override
public String getDescription() {
return description;
}
}
heres how i used it to trigger button event. jFileSave is of type JFileChooser
try {
CustomFileFilter filter = new CustomFileFilter();
filter.setExtension(".xls");
filter.setDescription("Microsoft Excel 2003 Workbooks Only (*.xls)");
jFileSave.setFileFilter(filter); // here is where i get null pointer exception
int option = jFileSave.showSaveDialog(jLabel3);
if (option == jFileSave.APPROVE_OPTION) {
GenerateReport report = new GenerateReport(Integer.parseInt(jlstYear.getSelectedValue().toString()), jFileSave.getSelectedFile().toString() + filter.getExtension());
report.create_report();
jlblReport.setText("Report has been created");
report = null;
}
} catch (Exception ex) {
ex.printStackTrace();
jlblReport.setText("Report could not be created!");
}
}