获取错误:使用首选项时出现“错误的令牌异常”

时间:2013-12-13 08:40:37

标签: android android-preferences

我正在尝试向我的应用程序添加首选项页面。首选项屏幕包含两个列表首选项和一个复选框。

但是当我尝试单击列表首选项时,应用程序崩溃了。我不知道如何解决这个问题。任何人都可以帮助我....

来源:

package com.emergencyappbgi;

import com.emergencyappbgi.R;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;

public class Preferences extends PreferenceActivity
{

    static public final String PREF_RECORD_CALLS = "PREF_RECORD_CALLS";
    static public final String PREF_AUDIO_SOURCE = "PREF_AUDIO_SOURCE";
    static public final String PREF_AUDIO_FORMAT = "PREF_AUDIO_FORMAT";

    SharedPreferences prefs;

    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.userpreferences);
    }
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <CheckBoxPreference
        android:defaultValue="true"
        android:key="PREF_RECORD_CALLS"
        android:summary="Turn on recording of all calls"
        android:title="Enable recording" />

    <ListPreference
        android:defaultValue="1"
        android:dialogTitle="Audio source"
        android:entries="@array/audio_source_options"
        android:entryValues="@array/audio_source_values"
        android:key="PREF_AUDIO_SOURCE"
        android:summary="Select the audio source to record from during calls"
        android:title="Audio source" />
    <ListPreference
        android:defaultValue="1"
        android:dialogTitle="Audio format"
        android:entries="@array/audio_format_options"
        android:entryValues="@array/audio_format_values"
        android:key="PREF_AUDIO_FORMAT"
        android:summary="Select the file format to use for call recordings"
        android:title="Recording file format" />

</PreferenceScreen>

记录猫:

12-13 08:38:00.310: E/AndroidRuntime(2301): FATAL EXCEPTION: main
12-13 08:38:00.310: E/AndroidRuntime(2301): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@41522060 is not valid; is your activity running?
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.view.ViewRootImpl.setView(ViewRootImpl.java:567)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.app.Dialog.show(Dialog.java:281)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.preference.DialogPreference.showDialog(DialogPreference.java:308)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.preference.DialogPreference.onClick(DialogPreference.java:266)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.preference.Preference.performClick(Preference.java:949)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:215)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.widget.AdapterView.performItemClick(AdapterView.java:298)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.widget.AbsListView$1.run(AbsListView.java:3423)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.os.Handler.handleCallback(Handler.java:725)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.os.Looper.loop(Looper.java:137)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at android.app.ActivityThread.main(ActivityThread.java:5041)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at java.lang.reflect.Method.invokeNative(Native Method)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at java.lang.reflect.Method.invoke(Method.java:511)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-13 08:38:00.310: E/AndroidRuntime(2301):     at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案