Reputation: 143
I was working on the application and I used com.google.android.material.textfield.TextInputLayout
I got a very long error and my app crashed.
2021-05-28 17:29:49.913 23418-23418/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.a7minuteworkout, PID: 23418
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.a7minuteworkout/com.example.a7minuteworkout.BmiActivity}: android.view.InflateException: Binary XML file line #74 in com.example.a7minuteworkout:layout/activity_bmi: Binary XML file line #74 in com.example.a7minuteworkout:layout/activity_bmi: Error inflating class com.google.android.material.textfield.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3792)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3968)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8506)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1139)
Caused by: android.view.InflateException: Binary XML file line #74 in com.example.a7minuteworkout:layout/activity_bmi: Binary XML file line #74 in com.example.a7minuteworkout:layout/activity_bmi: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #74 in com.example.a7minuteworkout:layout/activity_bmi: 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:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.example.a7minuteworkout.BmiActivity.onCreate(BmiActivity.kt:21)
at android.app.Activity.performCreate(Activity.java:8198)
at android.app.Activity.performCreate(Activity.java:8182)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3765)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3968)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8506)
at java.lang.reflect.Method.invoke(Native Method)
2021-05-28 17:29:49.914 23418-23418/? E/AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1139)
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:115)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:463)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:422)
... 32 more
On seeing at I got error was where I initialized XML File in Kotlin File in OnCreate function setContentView(R.layout.activity_bmi)
. I debug the code by removing block of code where I used com.google.android.material.textfield.TextInputLayout
app doesn't crashed.
This is my XML File
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".BmiActivity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_bmi_activity"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#FFFFFF" />
<RadioGroup
android:id="@+id/rgUnits"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/radio_group_tab_background"
android:orientation="horizontal"
android:layout_below="@id/toolbar_bmi_activity">
<RadioButton
android:id="@+id/rb_metricUnits"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:background="@drawable/radio_button_tab_selector"
android:textColor="@drawable/drawable_unit_tab_text_color_selector"
android:checked="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16sp"
android:button="@null"
android:text="@string/metric_units"/>
<RadioButton
android:id="@+id/rb_usUnits"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:background="@drawable/radio_button_tab_selector"
android:textColor="@drawable/drawable_unit_tab_text_color_selector"
android:checked="false"
android:gravity="center"
android:textStyle="bold"
android:textSize="16sp"
android:button="@null"
android:text="@string/us_units"/>
</RadioGroup>
<LinearLayout
android:id="@+id/ll_units_view"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_below="@id/rgUnits"
android:padding="10dp">
<LinearLayout
android:id="@+id/llMetricUnitsView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilMetricUnitWeight"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etMetricUnitWeight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/weight_in_kg"
android:inputType="numberDecimal"
android:textSize="16sp"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilMetricUnitHeight"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etMetricUnitHeight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/height_in_cm"
android:inputType="numberDecimal"
android:textSize="16sp"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/llUsUnitsView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilUSUnitWeight"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etUSUnitWeight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/weight_in_lbs"
android:inputType="numberDecimal"
android:textSize="16sp"/>
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:id="@+id/ll_units_height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:baselineAligned="false"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilUSUnitHeightFeet"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_marginTop="10dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etUSUnitHeightFeet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/feet"
android:inputType="number"
android:textSize="16sp"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilUSUnitHeightInch"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_marginTop="10dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginStart="5dp"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etUSUnitHeightInch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/inch"
android:inputType="number"
android:textSize="16sp"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_display_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:orientation="vertical"
android:visibility="invisible"
tools:visibility="visible">
<TextView
android:id="@+id/tv_your_bmi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/your_bmi"
android:visibility="invisible"
android:textAllCaps="true"
android:textSize="16sp"/>
<TextView
android:id="@+id/tv_bmi_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="5dp"
android:text="@string/_15_00"
android:textStyle="bold"
android:textSize="18sp"/>
<TextView
android:id="@+id/tv_bmi_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="5dp"
android:text="@string/normal"
android:textStyle="bold"
android:textSize="18sp"/>
<TextView
android:id="@+id/tv_bmi_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="5dp"
android:text="@string/normal"
android:textStyle="bold"
android:textSize="18sp"/>
</LinearLayout>
<Button
android:id="@+id/btn_calculate_unit"
android:layout_marginTop="35dp"
android:textSize="18sp"
android:text="@string/calculate"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:backgroundTint="@color/colorAccent"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
Here, it is my dependencies
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
I have added Material Icon theme but after that showing error. So please help me.
Upvotes: 0
Views: 828
Reputation: 119
I suppose, you have to change in the manifest file android:theme of the .BmiActivity to android:theme=“@style/Theme.MaterialComponents.Light.NoActionBar”
Upvotes: 2