android getSharedPreferences error: Map value without name attribute: boolean

后端 未结 3 1968
囚心锁ツ
囚心锁ツ 2020-12-07 01:42

I am trying to figure out the cause of this error it occurs on startup when i try to get the shared preferences for the app. the code is just:

settings = this.getSha

相关标签:
3条回答
  • 2020-12-07 02:33

    In my case

    public static String docsDownloadStatus;
    
        SharedPreferences sharedPref = context.getSharedPreferences(
                "Pref-Values", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
    >>>>    editor.putString(docsDownloadStatus, value);
        editor.commit();
    

    "docsDownloadStatus" is not initialized because of this whole shared pref file was corrupted. After initializing docsDownloadStatus key everything worked fine.

    0 讨论(0)
  • 2020-12-07 02:34

    Are you able to reproduce this on emulator? If yes, then you could extract the prefs file using Eclipse DDMS tools to investigate the contents of the prefs file.

    0 讨论(0)
  • 2020-12-07 02:40

    thanks for the tip. the prefs file was

    <?xml version='1.0' encoding='utf-8' standalone='yes' ?>
    <map>
    <boolean value="false" />
    <boolean name="initialised" value="true" />
    <boolean name="upd.auto" value="true" />
    <long name="backup.last" value="1300662039054" />
    <string name="msg.read">0.995.18Beta</string>
    </map>
    

    turns out i was writing a null preference name to the prefs - so the error was correct - though I don't think the API should let you do that since the prefs cant be read after that.

    anyways, a bit of a schoolboy error, but got there ...

    thanks for the quick reply, rob

    0 讨论(0)
提交回复
热议问题