1

我似乎只是在 API 15 设备上收到此错误。这似乎是动画或其他东西的问题,但我不知道该怎么做才能解决这个问题。当我启动我的应用程序时,它会强制关闭。但是,在 API 17 上,它运行良好。

这是似乎导致它的行:

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

这是堆栈跟踪:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to create application com.ianmcdowell.googlevoicemessaging.MmsApp: android.view.InflateException: Binary XML file line #2: Error inflating class alpha
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3957)
    at android.app.ActivityThread.access$1300(ActivityThread.java:123)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class alpha
    at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:441)
    at android.preference.GenericInflater.inflate(GenericInflater.java:317)
    at android.preference.GenericInflater.inflate(GenericInflater.java:263)
    at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:269)
    at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:462)
    at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:440)
    at com.ianmcdowell.googlevoicemessaging.MmsApp.onCreate(MmsApp.java:65)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3954)
    ... 10 more
Caused by: java.lang.ClassNotFoundException: android.preference.alpha
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    at android.preference.GenericInflater.createItem(GenericInflater.java:375)
    at android.preference.GenericInflater.onCreateItem(GenericInflater.java:417)
    at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:428)
    ... 18 more

如果您需要更多信息,请告诉我...

编辑:preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
  xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory android:title="@string/pref_sms_appearance_title">
        <CheckBoxPreference android:title="@string/pref_title_darktheme" android:key="pref_key_darktheme" android:summary="@string/pref_summary_darktheme" android:defaultValue="false" />
    </PreferenceCategory>
    <PreferenceCategory android:title="@string/pref_sms_googlevoice_title" android:key="pref_key_storage_gvsettings">
        <CheckBoxPreference android:title="@string/pref_title_gv_enable" android:key="pref_key_gv_enable" android:summary="@string/pref_summary_gv_enable" android:defaultValue="false" />
        <ListPreference android:entries="@array/prefEntries_gvsendtextwith" android:title="@string/pref_sms_googlevoice_composewith_title" android:key="pref_key_gvSendViaPref" android:defaultValue="0" android:entryValues="@array/prefValues_gvsendtextwith" />
        <CheckBoxPreference android:title="@string/pref_title_gv_smartreply" android:key="pref_key_gv_smartreply" android:summary="@string/pref_summary_gv_smartreply" android:defaultValue="true" />
        <CheckBoxPreference android:title="@string/pref_title_gv_markasread" android:key="pref_key_gv_markasread" android:summary="@string/pref_summary_gv_markasread" android:defaultValue="false" />
        <Preference android:title="@string/pref_title_gv_settings" android:key="pref_key_sms_gv_settings" android:summary="@string/pref_summary_gv_settings" />
        <Preference android:title="@string/pref_title_gv_help" android:key="pref_key_sms_gv_help" android:summary="@string/pref_summary_gv_help" />
    </PreferenceCategory>
    <PreferenceCategory android:title="@string/pref_notification_settings_title">
        <CheckBoxPreference android:title="@string/pref_title_notification_enabled" android:key="pref_key_enable_notifications" android:summary="@string/pref_summary_notification_enabled" android:defaultValue="true" />
        <RingtonePreference android:layout="?android:preferenceLayoutChild" android:title="@string/pref_title_notification_ringtone" android:key="pref_key_ringtone" android:dependency="pref_key_enable_notifications" android:defaultValue="content://settings/system/notification_sound" android:ringtoneType="notification" />
        <ListPreference android:entries="@array/prefEntries_vibrateWhen" android:layout="?android:preferenceLayoutChild" android:title="@string/pref_title_notification_vibrateWhen" android:key="pref_key_vibrateWhen" android:summary="@string/pref_summary_notification_vibrateWhen" android:dependency="pref_key_enable_notifications" android:defaultValue="@string/prefDefault_vibrate_true" android:dialogTitle="@string/prefDialogTitle_vibrateWhen" android:entryValues="@array/prefValues_vibrateWhen" />
        <CheckBoxPreference android:title="@string/pref_title_popupnotification_enabled" android:key="pref_key_enable_popupnotifications" android:summary="@string/pref_summary_popupnotification_enabled" android:dependency="pref_key_enable_notifications" android:defaultValue="true" />
    </PreferenceCategory>
    <PreferenceCategory android:title="@string/pref_sms_storage_title" android:key="pref_key_storage_settings">
        <CheckBoxPreference android:title="@string/pref_title_auto_delete" android:key="pref_key_auto_delete" android:summary="@string/pref_summary_auto_delete" android:defaultValue="false" />
        <Preference android:persistent="false" android:title="@string/pref_title_sms_delete" android:key="pref_key_sms_delete_limit" android:summary="@string/pref_summary_delete_limit" android:dependency="pref_key_auto_delete" />
        <Preference android:persistent="false" android:title="@string/pref_title_mms_delete" android:key="pref_key_mms_delete_limit" android:summary="@string/pref_summary_delete_limit" android:dependency="pref_key_auto_delete" />
    </PreferenceCategory>
    <PreferenceCategory android:title="@string/pref_sms_settings_title" android:key="pref_key_sms_settings">
        <CheckBoxPreference android:title="@string/pref_title_sms_delivery_reports" android:key="pref_key_sms_delivery_reports" android:summary="@string/pref_summary_sms_delivery_reports" android:defaultValue="false" />
        <Preference android:title="@string/pref_title_manage_sim_messages" android:key="pref_key_manage_sim_messages" android:summary="@string/pref_summary_manage_sim_messages" />
    </PreferenceCategory>
    <PreferenceCategory android:title="@string/pref_mms_settings_title" android:key="pref_key_mms_settings">
        <CheckBoxPreference android:title="@string/pref_title_mms_delivery_reports" android:key="pref_key_mms_delivery_reports" android:summary="@string/pref_summary_mms_delivery_reports" android:defaultValue="false" />
        <CheckBoxPreference android:title="@string/pref_title_mms_read_reports" android:key="pref_key_mms_read_reports" android:summary="@string/pref_summary_mms_read_reports" android:defaultValue="false" />
        <CheckBoxPreference android:title="@string/pref_title_mms_auto_retrieval" android:key="pref_key_mms_auto_retrieval" android:summary="@string/pref_summary_mms_auto_retrieval" android:defaultValue="true" />
        <CheckBoxPreference android:layout="?android:preferenceLayoutChild" android:title="@string/pref_title_mms_retrieval_during_roaming" android:key="pref_key_mms_retrieval_during_roaming" android:summary="@string/pref_summary_mms_retrieval_during_roaming" android:dependency="pref_key_mms_auto_retrieval" android:defaultValue="false" />
    </PreferenceCategory>

</PreferenceScreen>
4

1 回答 1

0

我知道这是一个老问题,但我想我会分享一个解决方案。

您的原始问题中提供的信息数量有限,但我相信此解决方案仍然适用。

我查看了有关创建首选项屏幕的指南(我假设您也这样做了)。本指南可在Android 开发人员指南网站上找到。

他们似乎错过了设置实际活动内容(如按钮、布局等屏幕组件)的调用,这些内容setContentView(View)Activity或 [AppCompatActivity][] 中使用。

TL;博士

添加到您的SettingsActivity.java文件中

setContentView(R.layout.my_settings_activity_layout);

对应布局文件my_settings_activity_layout的文件名在哪里MySettingsActivity.java

于 2018-12-23T16:19:28.810 回答