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;
    public boolean accept(File f) {
        return f.isDirectory() || f.getAbsolutePath().endsWith(extension);
    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.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());
                jlblReport.setText("Report has been created");
                report = null;
            } catch (Exception ex) {
            jlblReport.setText("Report could not be created!");

Not being able to see all of your code, my first guess is that jFileSave has not been instantiated. Also, what is your CustomFileFilter extending? Are you sure you have initialized it correctly?

Without a stack trace, it's hard for me to guess where the problem might lie.

It would help if you told us the line number where the NPE is thrown.

thanks to dononelson managed to find the error. was a silly mistake of not instantiating. :D