Closed sajid-verveba closed 6 years ago
add .withStartFile(startingDir)
Experiencing the same here. Log is;
java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File[] java.io.File.listFiles(java.io.FileFilter)' on a null object reference at com.obsez.android.lib.filechooser.ChooserDialog.listDirs(ChooserDialog.java:288) at com.obsez.android.lib.filechooser.ChooserDialog.refreshDirs(ChooserDialog.java:371) at com.obsez.android.lib.filechooser.ChooserDialog.build(ChooserDialog.java:204)
My code is:
btnUpload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new ChooserDialog().with(getActivity())
.withStartFile("")
// .withStartFile(Environment.getExternalStorageState()+"/")
.withFilterRegex(false, false, ".*\\.(jpe?g|png)")
.withChosenListener(new ChooserDialog.Result() {
@Override
public void onChoosePath(String path, File pathFile) {
Toast.makeText(getContext(), "FILE: " + path, Toast.LENGTH_SHORT).show();
}
})
.build()
.show();
.............................
Kindly assist.
EDIT:
It failed even with .withStartFile(Environment.getExternalStorageState()+"/")
it seems that caused by _currentDir
is null, in ChooserDialog.java#L312: File[] files = _currentDir.listFiles(_fileFilter);
, with an earlier version used. so:
1.1.9
just checked: withStartFile("")
cause _currentDir == null
.
as a workaround, replace it with withStartFile(null)
or .withStartFile(Environment.getExternalStorageDirectory().getAbsolutePath())
.
Crash Error : -
Following code used in fragment : -