Android, can't load multiple PImages from folder

edited March 2018 in Android Mode

Hey, I want to load multiple images from a subfolder into a PImage array. In JavaMode it works without problems.

But when using Android Mode and uploading it to the phone I get a NullPointerException in line 17. So filenames probably won't be created. Why? I have no idea what to further try..

String[] filenames;
PImage[] img;

void setup() {
  String imagepath = dataPath("images") + "/";
  File folder = new File(imagepath);

  // filter (returns true if file's extension is .jpg)
  java.io.FilenameFilter pngFilter = new java.io.FilenameFilter() {
    public boolean accept(File dir, String name) {
      return name.toLowerCase().endsWith(".png");
    }
  };
  filenames = folder.list(pngFilter);

  // define array size
  img = new PImage[filenames.length];
  for (int i = 0; i < filenames.length; i++) {
    println(imagepath + filenames[i]);
    img[i] = loadImage(imagepath + filenames[i]);
  }
}

void draw() {
}

BUILD SUCCESSFUL in 19s 28 actionable tasks: 28 executed FATAL EXCEPTION: Animation Thread Process: processing.test.test, PID: 517 java.lang.NullPointerException: Attempt to get length of null array at processing.test.test.test.setup(test.java:37) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PSurfaceNone.callDraw(Unknown Source) at processing.core.PSurfaceNone$AnimationThread.run(Unknown Source)

Tagged:

Answers

Sign In or Register to comment.