0
我想從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>
請發佈拋出異常的完整logcat。 – Egor 2012-03-02 17:11:17
請參閱編輯 – Jaume 2012-03-02 17:35:47
編輯器做了什麼?發佈您的佈局和完整的代碼,並查看您的佈局(二進制XML文件行#2)。 – Sunny 2012-03-02 17:41:47