Symbian/Phonegaps-1.10 | TypeError: Result of expression 'localStorage' [null] is not an object

457 views Asked by At

I get

TypeError: Result of expression 'localStorage' [null] is not an object

when I try access to localStorage on Symbian/Phonegap app Looks like this related to error that ocurr before:

TypeError: Result of expression 'window.widget.preferenceForKey' [undefined] is not a function. that ocurr in line var pref = window.widget.preferenceForKey(Storage.PREFERENCE_KEY);

function Storage() {
    this.available = true;
    this.serialized = null;
    this.items = null;

    if (!window.widget) {
        this.available = false;
        return;
    }
    var pref = window.widget.preferenceForKey(Storage.PREFERENCE_KEY);

    //storage not yet created
    if (pref == "undefined" || pref == undefined) {
        this.length = 0;
        this.serialized = "({})";
        this.items = {};
        window.widget.setPreferenceForKey(this.serialized, Storage.PREFERENCE_KEY);
    } else {
        this.serialized = pref;'({"store_test": { "key": "store_test", "data": "asdfasdfs" },})';
        this.items = eval(this.serialized);
    }
}

It seems that I need to resolve local storage I don `t know how to do it. Any workaround?

1

There are 1 answers

0
Prokenyan On BEST ANSWER

I have actually struggled with this problem myself.

A simple work around is to avoid preferenceForKey all together and instead use preference.

<script>
    var value = "Information to be stored";
    var key = "key";
    widget.preference["key"] = value;
 </script>

You can the retreive this information later.

<script>
    var value = widget.preference["key"];
    alert(value);
</script>

Hope this helps!