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?
I managed to solve it by storing my app files in /mnt/sdcard/Android/data/com.myapp.android/
folder. This location will be private to my app, and will be cleared when the app is uninstalled.
Now, I can read/write files from javascript using cordova's File plugin, and a file path will be like: Android/data/com.myapp.android/abc.txt
. Since File plugin considers Compatibility
as the default value for preference AndroidPersistentFileLocation
in config.xml, the persistent file store will be returned as /mnt/sdcard
(if mounted), which is by default in Android.
Reference: Google groups link