简体   繁体   中英

Eclipse doesn't recognize listFiles(Filter paramFileFilter)

How can I fix this? Eclipse doesn't recognize this function:

listFiles(Filter paramFileFilter)

See these screenshots:

在此处输入图片说明


在此处输入图片说明

Check the type of FileFilter ; chances are that it's not java.io.FileFilter

In such cases always check the import statements for the involved method and arguments. Chances are high you imported some xyFileFilter, but wanted abFileFilter. You can most easily do the check by hovering over the identifiers and the method call, where you will see the fully qualified name.

This error happens mostly when using the wrong quick fix when creating those imports in Eclipse, so make sure to select the correct "Import XYZ" quick fix by looking at the package name in braces at the end of the tool tip.

Many years later, but I just hit this same problem myself. My problem was that I created a file filter to use with JFileChooser, and then I tried to use the same filter with File.listFiles. The problem is that there are two different classes both called "FileFilter", or rather, a class and an interface.

JFileChooser uses javax.swing.filechooser.FileFilter. File.listFiles uses java.io.FileFilter.

But fortunately, both require a function with signature public boolean accept(File f). So the solution is easy enough. I change my file filter from "extends javax.swing.filechooser.FileFilter" to "extends javax.swing.filechooser.FileFilter implements java.io.FileFilter". Then it works for both cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM