android設置來自xml文件的共享首選項崩潰

[英]android set shared preferences from an xml file crashes


I am trying to set shared_prefs from an xml file but, when simulating, app crashes returning a lot of error messages starting from: FATAL EXCEPTION: main.

我試圖從xml文件設置shared_prefs但是,在模擬時,app崩潰返回了很多錯誤消息,從:FATAL EXCEPTION:main。

@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); 

errors:

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

and many more.

還有很多。

prefs.xml

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

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

1 个解决方案

#1


0  

<map> is not a valid tag for preferences.xml.

不是preferences.xml的有效標記。

See an example here.

在這里查看示例。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/03/02/f5ecd372c4111dc1f9decbe286e115b0.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com