views:

260

answers:

1
+2  Q: 

Java FileFilter

public class DocFilter extends FileFilter {
    public boolean accept(File f) {
        if (f.isDirectory()) {
            return true;
        }

        String extension = Utils.getExtension(f);
        if (extension != null) {
            if (extension.equals(Utils.doc) ||
                extension.equals(Utils.docx) )
            {
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    //The description of this filter
    public String getDescription() { return "Just Document Files"; }
}

Netbeans compiler warned with the error, "No interface expected here" for above code

Anyone has idea what was the problem?? I tried changing the 'extends' to 'implements', however, it didn't seem to work that way.

and when I changed to implements, the following code cannot work,

chooser.addChoosableFileFilter(new DocFilter());

and with this error,

"method addChoosableFileFilter in class javax.swing.JFileChooser cannot be applied to given types required: javax.swing.filechooser.FileFilter"

Can anyone help on this? Thanks..

+3  A: 

medoapl brings me the answer.

JFileChooser expects a javax.swing.filechooser.FileFilter when your imports must state you use a java.io.FileChooser. The first is a class, and the second an interface. So, replace the second by the first in your import.

Riduidel
Most likely. Cleaning up the imports could eliminate the problem!
Andreas_D
OMG~! I overlooked that part since Netbeans suggested the io library as the first choice and I accepted it. I suspected that already...Thanks a lot Riduidel..^^
Mr CooL