ArrayList<File> files = allFiles(Environment.getExternalStorageDirectory());
private ArrayList<File> allFiles(File root){
    ArrayList<File> arrayList = new ArrayList<>();
    File files[] = root.listFiles();
    for(File file:files){
        if(file.isDirectory()){
            arrayList.addAll(allFiles(file));
        }else{
            arrayList.add(file);
        }
    }
    return arrayList;
}
I am trying to list out all of the files on my android device. the above code, some exception is raised:
2020-01-24 15:20:31.048 23877-23877/com.example.readingfromstorage E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.readingfromstorage, PID: 23877 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.readingfromstorage/com.example.readingfromstorage.MainActivity}: java.lang.NullPointerException: Attempt to get length of null array
please help me to solve this problem. thanks;
 
     
    