SelectFile library generates a “FATAL EXCEPTION: main” error

Running the example sketch (provided on the Processing website) “Select_All_Features” using the SelectFile library on my Android phone (Moto g7/Android 10) I get an error. When I tap one of the icons on the screen e.g. to open a folder etc, then the sketch crashes generating “FATAL EXCEPTION: main” error apparently for a "Attempt to get length of null array. Any suggestions to avoid this are welcome. Thanks.
UPDATE: Even the most simple application of this library generates the error (see code and error console)

import select.files.*;
SelectLibrary files;

void setup() {
fullScreen();

files = new SelectLibrary(this);

files.selectInput(“Select a file to process:”, “fileSelected”);
// files.selectFolder(“Select a folder to process:”, “fileSelected”);
// files.selectOutput(“Save the file please:”, “fileSelected”);
}
void fileSelected(File selection) {
if (selection == null) {
println(“Nothing was selected.”);
} else {
println("User selected " + selection.getAbsolutePath());
}
}

BUILD SUCCESSFUL in 9s
25 actionable tasks: 25 executed
FATAL EXCEPTION: main
Process: processing.test.test01, PID: 21829
java.lang.NullPointerException: Attempt to get length of null array

  • at java.util.Arrays.sort(Arrays.java:1424)*
  • at select.files.SelectDialog.sortData(Unknown Source:2)*
  • at select.files.SelectDialog.getData(Unknown Source:17)*
  • at select.files.SelectDialog.updateCurrentList(Unknown Source:0)*
  • at select.files.SelectDialog.onCreate(Unknown Source:126)*
  • at android.app.Dialog.dispatchOnCreate(Dialog.java:421)*
  • at android.app.Dialog.show(Dialog.java:315)*
  • at select.files.SelectLibrary$1.run(Unknown Source:13)*
  • at android.os.Handler.handleCallback(Handler.java:883)*
  • at android.os.Handler.dispatchMessage(Handler.java:100)*
  • at android.os.Looper.loop(Looper.java:241)*
  • at android.app.ActivityThread.main(ActivityThread.java:7617)*
  • at java.lang.reflect.Method.invoke(Native Method)*
  • at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)*
  • at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)*

Not sure as i havent used the lib, here is an alternative though.

Thank you for your suggestion, but for the moment I prefer to stick to the familiar field of processing examples.

If you are on android selectinput and selectfolder do not work.

Sorry for my late reply but can you please have a look at SelectFile and then try to explain me why it does not work.
Thanks

Woops i thought you were referring to selectInput.

You are welcome to try it however i have never tried it.

However i have tried my lib, and am comfortable with the methods.

It is of course entirely up to you so feel free to use whatever you prefer.

Please note that my lib also has a working text input class, called text area, ive made other posts on the forum if you want to see examples,

Also mine makes use of ala android file browser, and the only one ive found to be compatible is

File explorer by Xiaomi on the app store.

From the looks of things you probably have a problem as you havent set the permission requests in your sketch.

However the selectFile seems to have been made for an older version of android and its likely it wont work without choosing an alternative method for permission requests.

Please see their example sketch to see what i mean.

*
 * This minimalistic sketch shows how to use `selectFile()` on Android.
 * 
 * This sketch requires the READ_EXTERNAL_STORAGE permission to be selected
 * through the Sketch Permissions list in the PDE, and then to use the requestPermission()
 * function in the code, since READ_EXTERNAL_STORAGE is a dangerous permission that must
 * be requested during run-time in Android 23 and newer:
 * https://developer.android.com/guide/topics/permissions/requesting.html#normal-dangerous 
 */

import select.files.*;

SelectLibrary files;

void setup() {
  size(displayWidth, displayHeight);

  files = new SelectLibrary(this);
//these are the permissions you need but since api 28
//you have to request user input to confirm them. 
//The link i have provided should include a 
//permission class to address this problem.
  if (!hasPermission("android.permission.READ_EXTERNAL_STORAGE")) {
    requestPermission("android.permission.READ_EXTERNAL_STORAGE", "handleRequest");
  }

  // files.selectFolder("Select a folder to process:", "fileSelected");
  // files.selectOutput("Save the file please:", "fileSelected");
}

void handleRequest(boolean granted) {
  if (granted) {
    files.selectInput("Select a file to process:", "fileSelected");
  } else {
    println("Does not have permission to read external storage.");
  }
}

void fileSelected(File selection) {
  if (selection == null) {
    println("Nothing was selected.");
  } else {
    println("User selected " + selection.getAbsolutePath());
  }
}

Again sorry for a late answer, this is probably due to the fact that I am getting more and more frustrated with this problem which by the way I posted already 7 years ago on the predecessor of this forum. Any way, thank you for your help.
The code you provided is the code that can be found on the Ostap Andrusiv page where you were so kind to comment on the importance of a proper handling of the permission requests. It is this code that I have tried several times (sorry the code at the top of my post is incomplete in that respect). Building the sketch works and a message appears on the phone asking to confirm the permissions set. Once accepted, the sketch will crash and the errors as mentioned above will appear.
Have you successfully tried this code?
regards
marc

not sure how the lib works honestly, and I don’t feel like digging around in it to understand why, as I currently have a working solution. Is it the best probably not, does it allow me to pick a file or a folder yes. Image text etc, no problem. Of course this is just my personal taste.


import select.files.*;

SelectLibrary files;

void setup() {
  size(displayWidth, displayHeight);
  Permission p = new Permission(this, "WRITE_EXTERNAL_STORAGE");
  p = new Permission(this, "READ_EXTERNAL_STORAGE");
  files = new SelectLibrary(this);

  //files.selectFolder("Select a folder to process:", "fileSelected");
  //files.selectOutput("Save the file please:", "fileSelected");
};

void mousePressed() {
  files.selectFolder("Select a folder to process:", "fileSelected");
  //selectInput("Select a file to process:", "fileSelected");
  files.selectOutput("Save the file please:", "fileSelected");
};

void handleRequest(boolean granted) {
  if (granted) {
    println("1");
    files.selectInput("Select a file to process:", "fileSelected");
  } else {
    println("Does not have permission to read external storage.");
  }
};

void fileSelected(File selection) {
  if (selection == null) {
    println("Nothing was selected.");
  } else {
    println("User selected " + selection.getAbsolutePath());
  }
};

this is the permission class remember you also need to set permission in processing’s ide.

public class Permission{
  
  PApplet parent;
  String p;

  public Permission(PApplet pParent,String permissionName) {
    parent = pParent;
    p = permissionName;
    parent.requestPermission("android.permission."+permissionName, "onPermissionResult", this);
  };

  public void onPermissionResult(boolean granted) {
    if (!granted) {
      PApplet.println("User did not grant", p ,"permission.", p ,"is disabled.");
    }
  };

};

However the code above doesnt work even with permissions.