android.view.InflateException:错误夸大类android.widget.EditText华硕Android 5

我不断收到有关此崩溃发生的报告,但它仅在使用Android 5的华硕设备上发生,如下图所示
android.view.InflateException:错误夸大类android.widget.EditText华硕Android 5

那是堆栈跟踪:

    Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my_package/com.my_package.activities.SignInActivity}: android.view.InflateException: Binary XML file line #29: Error inflating class android.widget.EditText
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2326)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
       at android.app.ActivityThread.access$800(ActivityThread.java:147)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5264)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)
Caused by android.view.InflateException: Binary XML file line #29: Error inflating class android.widget.EditText
       at android.view.LayoutInflater.createView(LayoutInflater.java:633)
       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at android.view.View.inflate(View.java:18427)
       at com.my_package.activities.SignInActivity.onCreate(SignInActivity.java:52)
       at android.app.Activity.performCreate(Activity.java:5975)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
       at android.app.ActivityThread.access$800(ActivityThread.java:147)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5264)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)
Caused by java.lang.reflect.InvocationTargetException
       at java.lang.reflect.Constructor.newInstance(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at android.view.LayoutInflater.createView(LayoutInflater.java:607)
       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at android.view.View.inflate(View.java:18427)
       at com.my_package.activities.SignInActivity.onCreate(SignInActivity.java:52)
       at android.app.Activity.performCreate(Activity.java:5975)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
       at android.app.ActivityThread.access$800(ActivityThread.java:147)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5264)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)
Caused by java.lang.RuntimeException: Failed to resolve attribute at index 96
       at android.content.res.TypedArray.getColor(TypedArray.java:401)
       at android.widget.TextView.<init>(TextView.java:714)
       at android.widget.EditText.<init>(EditText.java:65)
       at android.widget.EditText.<init>(EditText.java:61)
       at android.widget.EditText.<init>(EditText.java:57)
       at java.lang.reflect.Constructor.newInstance(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at android.view.LayoutInflater.createView(LayoutInflater.java:607)
       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at android.view.View.inflate(View.java:18427)

SignInActivity.java

@Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_in);

        llSignInContainer = (LinearLayout) findViewById(R.id.llSignInContainer);
        llSignInContainer.addView(View.inflate(this, R.layout.sign_in_form, null)); // <-- Line 52
    }

sign_in_form.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_below="@+id/rlTop"
    android:background="@android:color/white"
    android:orientation="vertical"
    android:padding="@dimen/activity_horizontal_margin">

    <TextView
        android:id="@+id/tvHeader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/activity_horizontal_margin"
        android:layout_marginTop="@dimen/activity_horizontal_margin"
        android:padding="@dimen/edit_text_padding"
        android:text="@string/type_data_to_access_central"
        android:textColor="@color/mediumGray" />

    <android.support.design.widget.TextInputLayout
        android:id="@+id/inputEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/TextInputStyle"
        app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
        app:passwordToggleEnabled="false">

        <EditText // -- This is line 29 --
            android:id="@+id/etEmail"
            style="@style/FormEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/your_email"
            android:inputType="textEmailAddress" />
    </android.support.design.widget.TextInputLayout>

在其他设备上,它运行良好,并且我在华硕的Android 4.3和6.0设备上进行了测试,并且运行良好.

解决方法:

如关于这个答案的评论所说
https://*.com/a/30914037/5178257
问题出在主题上,因此,如果将父主题设置为ThemeOverlay.AppCompat.Light,它将解决ASUS设备上的崩溃问题.

例如

<style name="TextInputStyle" parent="ThemeOverlay.AppCompat.Light">
  <item name="android:textColorHint">@color/black</item>     
  <item name="colorControlActivated">@color/gray</item>
</style>
上一篇:请解释Java中的RuntimeException以及它应该在何处使用


下一篇:常见的几种RuntimeException