NullPointerException - Attempt to get length of null array (readDirectory())

前端 未结 2 1576
甜味超标
甜味超标 2021-01-01 22:05

I have the code as shown here. My Problem is a NullPointerException at files.length

for(int i=0; i < files.length; i++){

It is caused b

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-01 22:34

    f.listFiles()
    

    will return null if the path does not exist.

    Please check your path.

    Update

    Android will also require a permission to read certain files. Maybe you need to add this to your manifest:

     
    

    More information:

    http://developer.android.com/reference/android/Manifest.permission.html

提交回复
热议问题