开发者

android getSharedPreferences error: Map value without name attribute: boolean

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.getSharedPreferences(Globals.PREFS_NAME, 0)

Seems like a corruption, but the bug is in the app as i have installed it on multiple devices and the same error occurs. I have uninstalled the app and re-installed it to no avail. also did a fully clean build. I googled the error and dont seem to be able to find anything on it.

I was previously working fine. so I am a rather stumped. Any leads would be very highly appreciated ...

regards,

rob

W/ApplicationContext( 1541): getSharedPreferences
W/ApplicationContext( 1541): org.xmlpull.v1.XmlPullParserException: Map value without name attribute: boolean
W/ApplicationContext( 1541):    at com.android.internal.util.XmlUtils.readThisMapXml(XmlUtils.java:521)
W/ApplicationContext( 1541):    at com.android.internal.util.XmlUtils.readThisValueXml(XmlUtils.java:733)
W/ApplicationContext( 1541):    at com.android.internal.util.XmlUtils.readValueXml(XmlUtils.java:667)
W/ApplicationContext( 1541):    at com.android.internal.util.XmlUtils.readMapXml(XmlUtils.java:470)
W/ApplicationContext( 1541):    at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:376)
W/ApplicationContext( 1541):    at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:146)
W/ApplicationContext( 1541):    at net.robmunro.mypod.WelcomeActivity.onEWCreate(WelcomeActivity.java:160)
W/ApplicationContext( 1541):    at net.robmunro.mypod.AbstractEWActivity.onCreate(AbstractEWActivity.java:25)
W/ApplicationContext( 1541):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/ApplicationContext( 1541):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
W/ApplicationContext( 1541):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
W/ApplicationContext( 1541):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
W/ApplicationContext( 1541):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
W/ApplicationContext( 1541):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/ApplicationContext( 1541):    at android.os.Looper.开发者_开发问答loop(Looper.java:123)
W/ApplicationContext( 1541):    at android.app.ActivityThread.main(ActivityThread.java:3683)
W/ApplicationContext( 1541):    at java.lang.reflect.Method.invokeNative(Native Method)
W/ApplicationContext( 1541):    at java.lang.reflect.Method.invoke(Method.java:507)
W/ApplicationContext( 1541):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
W/ApplicationContext( 1541):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
W/ApplicationContext( 1541):    at dalvik.system.NativeStart.main(Native Method)


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.


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜