Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have two activities: In the first activity I am passing the String "pathName" to a second activity. I am receiving the extra okay and I can create a File from this path name. The problem arises when I try to call .listFiles() from that file.

Code: First Activity

    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

            String pathToSend = albumDirectory+albumList.get(position);
            Intent i = new Intent(getBaseContext(),GalleryImageSlider.class);
            i.putExtra("pathName", pathToSend);
            startActivity(i);
        }

Second Activity:

    List<File> imageList;

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_capture_gallery);

    Intent i = getIntent();
    filePath = i.getExtras().getString("pathName");
    albumFile = new File(filePath);

    Log.d("Fragment","File Path: " + albumFile.getAbsolutePath());
            //I can see this directory on my tablet, and I can see the files within. So the file
            path is correct

    try{
        imageList = Arrays.asList(albumFile.listFiles());

    }
    catch(NullPointerException e){
        Log.e("Error", "NPE: " + e);
    }

I understand that .listFiles returns null if there are no files to be read. But there are files, and I can see them when I look in my tablets file manager.

Anyone see a way to resolve this? Thanks before hand.

share|improve this question
add comment (requires an account with 50 reputation)

1 Answer

You could be possibly missing the PERMISSON to do so, listFiles() return null is some cases such the directory can not be found or you dont have permission to access to that directory. Check your PERMISSION in AndroidManifest.xml. Have you add the READ_EXTERNAL_STORAGE for the permission? Hope this helps.

share
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.