Frage

When I try to use the method someFile.listFiles(FileFilter foobar) I get the error

The method listFiles(FilenameFilter) in the type File is not applicable for the arguments (FileFilter)

While the javadoc of File clearly contains: public File[] listFiles(FileFilter filter) (http://docs.oracle.com/javase/7/docs/api/java/io/File.html)

How do I solve this?

PS: My code is:

    FileFilter folderFilter = new FileFilter() {
        public boolean accept(File file) {
            return file.isDirectory();
        }
        @Override
        public String getDescription() {
            return "some filter";
        }
    };
    File[] foobars = someFile.listFiles(folderFilter);
War es hilfreich?

Lösung

Looks like you've imported

javax.swing.filechooser.FileFilter

instead of

java.io.FileFilter

Probably occurred when selecting the import from the IDE

If the correct import is used, the code should not compile due to the existence of the getDescription method which is only found in the former. The description is used for display purposes on JFileChooser dialogs and doesnt apply here.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top