Android 添加首选项会使我的应用程序失败

Android 添加首选项会使我的应用程序失败,android,android-preferences,Android,Android Preferences,我刚刚在我的应用程序中添加了首选项,但它无法打开(即显示黑屏或意外停止)。 通过注释掉一些行,我发现问题在于首选项的初始化 //some imports here public class MyApp extends Activity { ..... SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); ...... } 一旦我把这行注释掉,一切(除了偏好)都很好

我刚刚在我的应用程序中添加了首选项,但它无法打开(即显示黑屏或意外停止)。 通过注释掉一些行,我发现问题在于首选项的初始化

//some imports here
public class MyApp extends Activity {
 ..... 
  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
  ......
  }
一旦我把这行注释掉,一切(除了偏好)都很好。 Logcat向我显示了一些错误(如20),但现在它没有显示错误,但应用程序仍然没有加载

编辑: 这是preferences.xml(在xml文件夹下)


这是布局文件夹下的array.xml


JPEG
GIF
jpg先生
.gif
讽刺的是,我现在无法让logcat给我错误。它只是不加载。如果我删除这一行(SharedReferences…),它将正常工作

你知道哪里不对吗


谢谢

显示更多代码。您的首选项声明正确Logcat trace也是必需的您是否正在初始化
SharedReferences
inside
onCreate()
…?不,它是在onCreate()之前,只是更改了它并且可以工作,谢谢!
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <ListPreference 
        android:key="format"
        android:title="Saving Format"
        android:summary="Select the file format"
        android:defaultValue="jpg" 
        android:entries="@array/format"
        android:entryValues="@array/formatValues"

    />    

</PreferenceScreen>
<resources>

    <string-array name="format">
        <item name="jpg">JPEG</item>
        <item name="gif">GIF</item>

    </string-array>

    <string-array name="formatValues">
        <item name="jpg">.jpg</item>
       <item name="gif">.gif</item>

      </string-array>

</resources>