Illegal access exception with LocalStorage on Android Gingerbread Illegal access exception with LocalStorage on Android Gingerbread android android

Illegal access exception with LocalStorage on Android Gingerbread


The illegal exception was caused by JSON.parse() methods when the .getItem() returns null. Just be careful to validate it. Android 2.3, HTML5 localStorage and Phonegap are working perfectly now.


Check the code for your WebView's WebSettings, i.e check the following are called:

WebSettings settings = webView.getSettings();settings.setJavaScriptEnabled(true);settings.setDatabaseEnabled(true);settings.setDatabasePath(this.getApplicationContext()        .getDir("database", Context.MODE_PRIVATE).getPath());settings.setDomStorageEnabled(true);


This validation work for me. :) (javascript in android 2.3 use phonegap)

Storage.prototype.getArray = function(key) {        if (this.getItem(key)) {            return JSON.parse(this.getItem(key))         } else {            //console.log("no error null value");        }    }