Hi guys... I followed a tutorial on posting pictures in my app... So I have been tracking a problem and am not sure what is going on, Could you please tell me or show me, or even point me in the right direction...
the error points to another section but I traced it to an empty array:
so I have an Filepaths class:
in another Class I call am getting my file directories and file paths:
Could anyone please tell me why
the error points to another section but I traced it to an empty array:
so I have an Filepaths class:
Java:
public class FilePaths {
//"storage/emulated/0"
public String ROOT_DIR = Environment.getExternalStorageDirectory().getPath();
public String PICTURES = ROOT_DIR + "/Pictures";
public String CAMERA = ROOT_DIR + "/DCIM/camera";
public String FIREBASE_IMAGE_STORAGE = "photos/users/";
}
in another Class I call am getting my file directories and file paths:
Code:
/**
* Search a directory and return a list of all **directories** contained inside
* @param directory
* @return
*/
public static ArrayList<String> getDirectoryPaths(String directory){
ArrayList<String> pathArray = new ArrayList<>();
File file = new File(directory);
File[] listfiles = file.listFiles();
for(int i = 0; i < listfiles.length; i++){
if(listfiles[i].isDirectory()){
pathArray.add(listfiles[i].getAbsolutePath());
}
}
return pathArray;
}
/**
* Search a directory and return a list of all **files** contained inside
* @param directory
* @return
*/
public static ArrayList<String> getFilePaths(String directory){
ArrayList<String> pathArray = new ArrayList<>();
File file = new File(directory);
File[] listfiles = file.listFiles();
Log.d(TAG, "getFilePaths: in file search");
if(listfiles != null){
for(int i = 0; i < listfiles.length; i++) {
if (listfiles[i].isFile()) {//the error traces back here where it is telling me the listfiles are empty??
pathArray.add(listfiles[i].getAbsolutePath());
} else {
Log.d(TAG, "getFilePaths: listfiles array is equal to null");
}
}
}
return pathArray;
}
Could anyone please tell me why
are empty???listfiles
Last edited: