Processing 3 and java.io.FilenameFilter;

edited September 2015 in Questions about Code

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

  • edited September 2015 Answer ✓

    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 not null 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?

Sign In or Register to comment.