react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

readDir called with null on Android yields `NullPointerException`

Open cancan101 opened this issue 10 years ago • 4 comments

java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
     at java.io.File.fixSlashes(File.java:183)
     at java.io.File.<init>(File.java:130)
     at com.rnfs.RNFSManager.readDir(RNFSManager.java:123)
     at java.lang.reflect.Method.invoke(Native Method)

cancan101 avatar Apr 11 '16 23:04 cancan101

@cancan101 what's the result on iOS? What is your expected result here?

johanneslumpe avatar Apr 24 '16 07:04 johanneslumpe

I get the similar result on android with the example code (it works with PicturesDirectoryPath)

RNFS.readDir(RNFS.MainBundlePath) .then((result) => { console.log('GOT RESULT', result); // stat the first file }).catch((err) => { console.log(err.message, err.code); }); } error: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference

tristola avatar May 20 '16 02:05 tristola

@tristola android not have MainBundlePath (see this), if you need to read assets, you can wait #83.

jhen0409 avatar May 20 '16 03:05 jhen0409

Created a pull request to have working example - PicturesDirectoryPath should exist in both platforms? #96

tristola avatar May 20 '16 03:05 tristola