[英]Binary XML file line #41: Error inflating class com.google.android.material.textfield.TextInputLayout
When I test my app and encounted this error and I tries many solutions provided in stackoverflow and did not worked.当我测试我的应用程序并遇到此错误时,我尝试了 stackoverflow 中提供的许多解决方案但没有奏效。 I thought it was a problem of version of material design, I upgraded to the latest version code of material design but it still does't work.我以为是material design的版本问题,我升级到material design的最新版本代码还是不行。
here is my App style这是我的应用风格
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar"></style>
And the design is below设计如下
<?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>
Here is the log I get:这是我得到的日志:
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)
Please I really need your help请我真的需要你的帮助
You forgot to close the RelativeLayout of the ScrollView您忘记关闭 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>
Also would like to suggest, use AppCompatImageView if you are using vector image as src.还想建议,如果您使用矢量图像作为 src,请使用 AppCompatImageView。 This is how we set the vector image.这就是我们设置矢量图像的方式。
<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.