I recently had a problem where a web app that worked fine on the iPhone, iPhone Simulator, Safari Mac, Safari Windows, Chrome and the Android Emulator would not work at all on any Android device. After tracking down someone who had an Android phone and was able to debug the app, we discovered:
Console: Uncaught illegal access
in the debugging output that was eventually traced back to a JSON.parse() call that had a null parameter. On all other platforms this returns null, on the Android device it throws an exception. See this bug report for details.
Moral of the story? Always explicitly check your parameter to JSON.parse() for null… and don’t trust the emulator!
Im experiencing the same problem. But it gets weirder in my case. Its working in the case im running Android Emulator on Linux but fails when i run the emulator on Windows….
I guess i’ll just add a check for JSON.parse null parameter then… 😦
Thanks for this. No doubt saved us some time.
In my case, its a little different. Its working on android emulator. But when I run it on any Android Mobile, it gives error “uncaught illegal access” at the line when I am doing
var menuJSON = JSON.parse(window.demo.function1(currentID));
function1 is not returns a JSONObject and it is not null.
Any help?
Thank you for this solution!
Thank you! This helped a bunch.
Wow! Thanks for saving our app in 2.2+ ! No emulator I tried had this problem, just the phone itself.
Ran into the same error … thought it was something to do with JSON / localStorage…. Googled it and ended up here.
Easy fix –
if ( localStorage.getItem(“something”)){
things = JSON.parse(localStorage.getItem(“something”));
}else{
things = [];
}
Kind of sucks because you can’t use the shorthand but better than a fatal bug!
an alternative fix may be:
var content = localStorage.getItem(‘something’);
content = content ? JSON.parse(content) : [];
Thanks, this was very useful, a frustrating bug to find!
Thanks, exactly the issue I just had! I assumed “illegal access” was to do with the storage, not the parsing…