Search code examples
androidcordovalocal-storageandroid-2.3-gingerbread

Illegal access exception with LocalStorage on Android Gingerbread


I made an Android/Phonegap app, and it is running fine on all devices with several android OS versions, except on some Gingerbread (2.3) phones. I am using Phonegap 1.9.

Debugging the code, I realized an illegal access exception on Javascript, every time I use the HTML5 localStorage.getItem() and localStorage.setItem() methods.

How can I enable the localStorage features on those Android devices?


Solution

  • 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.