Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullPointer Exception in Cordova 3.5 android File Plugin

I recently upgraded my cordova app from v2.9 to v3.5. I added the needed plugins through command line and did a cordova build of my app. I am getting a Nullpointer Exception when I read/write a file through file plugin. Below is the stack trace:

07-08 18:58:40.750: W/System.err(6670): java.lang.NullPointerException
07-08 18:58:40.750: W/System.err(6670):     at org.apache.cordova.file.LocalFilesystem.filesystemPathForURL(LocalFilesystem.java:67)
07-08 18:58:40.750: W/System.err(6670):     at org.apache.cordova.file.LocalFilesystem.getFileForLocalURL(LocalFilesystem.java:189)
07-08 18:58:40.750: W/System.err(6670):     at org.apache.cordova.file.FileUtils.getFile(FileUtils.java:749)
07-08 18:58:40.760: W/System.err(6670):     at org.apache.cordova.file.FileUtils.access$5(FileUtils.java:742)
07-08 18:58:40.760: W/System.err(6670):     at org.apache.cordova.file.FileUtils$16.run(FileUtils.java:397)
07-08 18:58:40.760: W/System.err(6670):     at org.apache.cordova.file.FileUtils$23.run(FileUtils.java:525)
07-08 18:58:40.760: W/System.err(6670):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-08 18:58:40.760: W/System.err(6670):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-08 18:58:40.760: W/System.err(6670):     at java.lang.Thread.run(Thread.java:856)

I need some immediate help here!!

Nullpointer Exception solved, but need help in file access

I would like to know, what should be the pattern of the url for a file access from the app's private package. In cordova 2.9, I was accessing it as /data/data/com.myapp.android/abc.txt from the Javascript. May I know what is the format of the url now in cordova 3.5?

like image 933
Rajesh Avatar asked Dec 15 '22 21:12

Rajesh


1 Answers

You need to add one of the following to your config.xml file

<preference name="AndroidPersistentFileLocation" value="Internal" />

<preference name="AndroidPersistentFileLocation" value="Compatibility" />

Check More details on this page It says

If your application has previously been shipped to users, using an older (pre- 1.0) version of this plugin, and has stored files in the persistent filesystem, then you should set the preference to "Compatibility". Switching the location to "Internal" would mean that existing users who upgrade their application may be unable to access their previously-stored files, depending on their device.

EDTT

You can try it this way,

cdvfile:///data/data/com.myapp.android

Check out

like image 138
gprathour Avatar answered Dec 22 '22 01:12

gprathour