android.view.InflateException:二进制XML文件行#2:错误导致类alpha

时间:2013-07-09 20:34:45

标签: android classnotfoundexception android-inflate

我似乎只在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>

1 个答案:

答案 0 :(得分:0)

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

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

我查看了有关创建首选项屏幕的指南(我假设您也这样做)。该指南可以在Android Developer Guides网站上找到。

他们似乎错过了设置Activity或[AppCompatActivity] []中使用的称为setContentView(View)的实际活动内容(按钮,布局等屏幕组件)的电话。 / p>

TL; DR

添加到您的SettingsActivity.java文件

setContentView(R.layout.my_settings_activity_layout);

其中my_settings_activity_layout是相应的MySettingsActivity.java布局文件的文件名