We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Having a Null pointer error here:
import java.io.FilenameFilter;
static final FilenameFilter pictFilter = new FilenameFilter() {
final String[] exts = {
".mov"
};
@ Override boolean accept(final File dir, String name) {
name = name.toLowerCase();
for (final String ext: exts) if (name.endsWith(ext)) return true;
return false;
}
};
protected static final File[] getFolderContent(final File dir) {
return dir.listFiles(pictFilter); // <--- Error here
}
Is there another way to filter files? P3 have issues with java.io class? Thanks for any help.
Answers
Just copied & pasted your code excerpt above in version 3.0b5 and it's successfully compiled & run. :-\"
Since pictFilter is initialized and it is
final
, it's notnull
for sure.For a NPE to happen, only if
null
is passed to parameter dir inside getFolderContent().i ran only this code and I got warnings around "(final File dir)" this snippet ran flawlessly before the update to 3. The dir variable appears only in those 3 instances in the code. in my case i have some .mov files, is the other thing i can think of about the NPE in my original code..
How do you run this code? Can you post an MCVE?