Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.listfiles giving a null exception (in app error could not read images) #3

Closed
vedant-creator opened this issue Sep 17, 2020 · 8 comments

Comments

@vedant-creator
Copy link

Hi Shubham,
I wanted to test the efficiency of facenet tf lite model so i tried running your app but it always gives the toast as " could not read images make sure you have files according to readme "

I rebuild your app and added the google services file, i added all the READ/WRITE permissions and i found that imageDir give the proper director but imageDir.listfiles return a null exception. I have directories in the images folder as specified but it is unable to list them

@shubham0204
Copy link
Owner

The imageDir.listFiles() method would throw a NullPointerException maybe because the imageDir is itself null. As you said you have created the images directory correctly, make sure you have created this directory in the device's internal storage and not the external storage.

@shubham0204
Copy link
Owner

You may rebuild the project to check if the issue is solved. See this commit.

@vedant-creator
Copy link
Author

I have no external sd card in my device, filepath which received in logcat was /storage/emaluated/0/images
i created folders in it as jeff_bezos and tested if it was a valid directory with isdirectory() it returned a true value, so I am not sure why .listfiles() method is returning null value

@vedant-creator
Copy link
Author

Okay i will try to rebuild it again

@vedant-creator
Copy link
Author

I tried the latest commit, still facing the same issue, I have added the logs for directory check and file path

 val imagesDir = File( Environment.getExternalStorageDirectory()!!.absolutePath + "/images" )
            val imagesSubDir1 = File( Environment.getExternalStorageDirectory()!!.absolutePath + "/images/vedant" )
            Log.w("fullpath", "" + imagesDir)
            if(imagesSubDir1.isDirectory){
                Log.w("fullpath", "yes" )
            }
            val imageSubDirs = imagesDir.listFiles()
            Log.w("fullpath", "" + imageSubDirs)
            if ( imageSubDirs == null ) {
                Toast.makeText( this , "Could not read images. Make sure you've have a folder as described in the README" ,
                        Toast.LENGTH_LONG ).show()
                return

Logcat output:

2020-09-17 21:34:51.211 16013-16013/com.ml.quaterion.facenetdetection W/fullpath: /storage/emulated/0/images
2020-09-17 21:34:51.211 16013-16013/com.ml.quaterion.facenetdetection W/fullpath: yes
2020-09-17 21:34:51.211 16013-16013/com.ml.quaterion.facenetdetection W/fullpath: null

@shubham0204
Copy link
Owner

@vedant-creator, thanks for the logs. I'll go through the issue once again and revert back to you. Also, please share your device's Android version so that I can resolve any issues with the API quickly.

@vedant-creator
Copy link
Author

I am using Android 10
Thank you for the efforts i hope the issue get solved

@vedant-creator
Copy link
Author

Hey @shubham0204 thanks for your support
I have solved the issue, in android 10 or API level above 29
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
android:requestLegacyExternalStorage="true"
needs to be added in manifest file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants