android设置来自xml文件的共享首选项崩溃

android设置来自xml文件的共享首选项崩溃

问题描述:

我想从xml文件设置shared_prefs,但是在模拟时,应用程序崩溃返回大量从以下错误消息开始:FATAL EXCEPTION:main。android设置来自xml文件的共享首选项崩溃

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     //first boot 
     SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); 
     SharedPreferences.Editor editor = settings.edit(); 

     PreferenceManager.setDefaultValues(this, R.xml.prefs, false); 

错误:

03-02 16:57:39.508: W/dalvikvm(15516): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 
03-02 16:57:39.528: E/AndroidRuntime(15516): FATAL EXCEPTION: main 
03-02 16:57:39.528: E/AndroidRuntime(15516): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testXml.com/com.testXml.com.PreferencesActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class map 

等等。

的prefs.xml

<?xml version='1.0' encoding='utf-8' standalone='yes' ?> 

<map> 
<string name="test">test</string> 
</map> 
+1

请发布抛出异常的完整logcat。 – Egor 2012-03-02 17:11:17

+0

请参阅编辑 – Jaume 2012-03-02 17:35:47

+0

编辑器做了什么?发布您的布局和完整的代码,并查看您的布局(二进制XML文件行#2)。 – Sunny 2012-03-02 17:41:47

<map>不是preferences.xml有效的标签。

查看示例here