java - Unable to open sd folder -




i list folders in external card push of button (currently hard coding location ball rolling)

public void onclickbtn(view v) {     file f = new file("/storage");     file[] files = f.listfiles();     (file infile : files) {         if (infile.isdirectory()) {             log.i("is directory", "here: " + infile);         }     } } 

this outputs logcat:

i/is directory: here: /storage/3164-6330 i/is directory: here: /storage/emulated i/is directory: here: /storage/private i/is directory: here: /storage/enc_emulated i/is directory: here: /storage/self 

now want repeat same process change path "/storage/3164-6330" because know that's sd card stores things

public void onclickbtn(view v) {     file f = new file("/storage/3164-6330");     file[] files = f.listfiles(); //will cause error here     (file infile : files) {         if (infile.isdirectory()) {             log.i("is directory", "here: " + infile);         }     } } 

but in logcat:

caused by: java.lang.nullpointerexception: attempt length of null array @ com.example.abc.mainactivity.onclickbtn(mainactivity.java:141) 

which line:

for (file infile : files) { 

does know why generating null array? have both files , folders in /storage/3164-6330 path. thanks!

listfiles() "the array empty if directory empty. returns null if abstract pathname not denote directory, or if i/o error occurs." -link

seems folder doesn't exist. think sdcard location depends on api using. mine storage/sdcard

you may want call: environment.getexternalstoragedirectory() sdcard location.

edit: apologize didn't see final line knowing exist. try environment.get call had similar issues , ended in call





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -