簡體   English   中英

二進制 XML 文件第 41 行:膨脹 class com.google.ZC31B32364CE19CA8FCD150A.

[英]Binary XML file line #41: Error inflating class com.google.android.material.textfield.TextInputLayout

當我測試我的應用程序並遇到此錯誤時,我嘗試了 stackoverflow 中提供的許多解決方案但沒有奏效。 我以為是material design的版本問題,我升級到material design的最新版本代碼還是不行。

這是我的應用風格

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar"></style>

設計如下

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/parent"
        tools:context=".user_ui.activities.LoginActivity">
        <com.mbula.animations.flowing_gradient.FlowingGradient
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:transition_duration = "4000"
            app:transition_drawable="@drawable/trans"
            />
        <ImageButton
            android:layout_margin="20dp"
            android:contentDescription="@string/todo"
            android:id="@+id/back"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="@drawable/awesome_rounded_background"
            android:src="@drawable/ic_arrow_back_white_24dp" />
        <ScrollView
            android:layout_centerInParent="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <RelativeLayout
                android:layout_gravity="center"
                android:layout_width="300dp"
                android:layout_height="wrap_content">
                <ImageView
                    android:contentDescription="@string/todo"
                    android:layout_centerHorizontal="true"
                    android:id="@+id/profil_image"
                    android:layout_width="80dp"
                    android:layout_height="80dp"
                    android:layout_marginBottom="10dp"
                    android:src="@drawable/ic_outline_account_circle_24" />
                <com.google.android.material.textfield.TextInputLayout
                    android:layout_below="@+id/profil_image"
                    android:id="@+id/username_wrapper"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    app:errorTextAppearance="@style/TextAppearance.Masolo.Design.Error"
                    app:hintTextAppearance="@style/TextAppearance.Masolo.Design.Hint"
                    app:startIconDrawable="@drawable/ic_phone_black_24dp">
                    <com.masolo.mbula.widgets.TextInputEditText
                        android:autofillHints="@string/t_l_phone_ou_email"
                        android:id="@+id/credential"
                        android:inputType="text"
                        android:background="@android:color/transparent"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:textSize="14sp"
                        android:hint="@string/t_l_phone" />
                </com.google.android.material.textfield.TextInputLayout>
 
        </ScrollView>
    </RelativeLayout>
</layout>

這是我得到的日志:

Process: com.masolo.mbula, PID: 4828
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.masolo.mbula/com.masolo.mbula.user_ui.activities.LoginActivity}: android.view.InflateException: Binary XML file line #41: Binary XML file line #41: Error inflating class com.google.android.material.textfield.TextInputLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2879)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2969)
        at android.app.ActivityThread.-wrap12(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1664)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6765)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:509)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: android.view.InflateException: Binary XML file line #41: Binary XML file line #41: Error inflating class com.google.android.material.textfield.TextInputLayout
     Caused by: android.view.InflateException: Binary XML file line #41: Error inflating class com.google.android.material.textfield.TextInputLayout
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
        at android.view.LayoutInflater.createView(LayoutInflater.java:647)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
        at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
        at com.masolo.mbula.user_ui.activities.LoginActivity.onCreate(LoginActivity.java:50)
        at android.app.Activity.performCreate(Activity.java:7025)
        at android.app.Activity.performCreate(Activity.java:7016)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1217)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2826)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2969)
        at android.app.ActivityThread.-wrap12(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1664)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6765)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:509)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f040000 a=4}
        at android.content.res.TypedArray.getDimension(TypedArray.java:627)
        at com.google.android.material.resources.TextAppearance.<init>(TextAppearance.java:77)

請我真的需要你的幫助

您忘記關閉 ScrollView 的 RelativeLayout

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

<RelativeLayout
    android:id="@+id/parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".user_ui.activities.LoginActivity">

    <com.mbula.animations.flowing_gradient.FlowingGradient
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:transition_drawable="@drawable/trans"
        app:transition_duration="4000" />

    <ImageButton
        android:id="@+id/back"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_margin="20dp"
        android:background="@drawable/awesome_rounded_background"
        android:contentDescription="@string/todo"
        android:src="@drawable/ic_arrow_back_white_24dp" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true">

        <RelativeLayout
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center">

            <ImageView
                android:id="@+id/profil_image"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="10dp"
                android:contentDescription="@string/todo"
                android:src="@drawable/ic_outline_account_circle_24" />

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/username_wrapper"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_below="@+id/profil_image"
                app:errorTextAppearance="@style/TextAppearance.Masolo.Design.Error"
                app:hintTextAppearance="@style/TextAppearance.Masolo.Design.Hint"
                app:startIconDrawable="@drawable/ic_phone_black_24dp">

                <com.masolo.mbula.widgets.TextInputEditText
                    android:id="@+id/credential"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:autofillHints="@string/t_l_phone_ou_email"
                    android:background="@android:color/transparent"
                    android:hint="@string/t_l_phone"
                    android:inputType="text"
                    android:textSize="14sp" />
            </com.google.android.material.textfield.TextInputLayout>
        </RelativeLayout>
    </ScrollView>
</RelativeLayout>
</layout>

還想建議,如果您使用矢量圖像作為 src,請使用 AppCompatImageView。 這就是我們設置矢量圖像的方式。

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/icon"
                android:layout_width="@dimen/_65dp"
                android:layout_height="@dimen/_65dp"
                android:layout_gravity="center"
                app:srcCompat="@drawable/ic_outline_account_circle_24"
                android:background="?selectableItemBackgroundBorderless" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM