简体   繁体   English

错误:充气 class com.google.android.material.textfield.TextInputLayout

[英]Error: Inflating class com.google.android.material.textfield.TextInputLayout

I am getting the error, here is my XML file我收到错误,这是我的 XML 文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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_below="@id/toolbar_bmi_activity"
        android:layout_margin="10dp"
        android:background="@drawable/drawable_radio_group_tab_background"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/rbMetricUnits"
            android:layout_width="0dp"
            android:layout_height="35dp"
            android:layout_weight="0.50"
            android:background="@drawable/drawable_units_tab_selector"
            android:button="@null"
            android:checked="true"
            android:gravity="center"
            android:text="METRIC UNITS"
            android:textColor="@drawable/drawable_units_tab_text_color_selector"
            android:textSize="16sp"
            android:textStyle="bold" />

        <RadioButton
            android:id="@+id/rbUsUnits"
            android:layout_width="0dp"
            android:layout_height="35dp"
            android:layout_weight="0.50"
            android:background="@drawable/drawable_units_tab_selector"
            android:button="@null"
            android:checked="false"
            android:gravity="center"
            android:text="US UNITS"
            android:textColor="@drawable/drawable_units_tab_text_color_selector"
            android:textSize="16sp"
            android:textStyle="bold" />
    </RadioGroup>

    <LinearLayout
        android:id="@+id/llUnitsView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/rgUnits"
        android:orientation="vertical"
        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="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_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp">

                <androidx.appcompat.widget.AppCompatEditText
                    android:id="@+id/etMetricUnitHeight"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="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="WEIGHT (in lbs)"
                    android:inputType="numberDecimal"
                    android:textSize="16sp" />
            </com.google.android.material.textfield.TextInputLayout>

            <LinearLayout
                android:id="@+id/llUsUnitsHeight"
                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_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:layout_weight="1">

                    <androidx.appcompat.widget.AppCompatEditText
                        android:id="@+id/etUsUnitHeightFeet"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="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_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="5dp"
                    android:layout_weight="1">

                    <androidx.appcompat.widget.AppCompatEditText
                        android:id="@+id/etUsUnitHeightInch"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Inch"
                        android:inputType="number"
                        android:textSize="16sp" />
                </com.google.android.material.textfield.TextInputLayout>

            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/llDiplayBMIResult"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:orientation="vertical"
            android:visibility="visible"
            tools:visibility="visible">

            <TextView
                android:id="@+id/tvYourBMI"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="YOUR BMI"
                android:textAllCaps="true"
                android:visibility="invisible"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/tvBMIValue"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:textSize="18sp"
                android:textStyle="bold"
                tools:text="15.00" />

            <TextView
                android:id="@+id/tvBMIType"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:textSize="18sp"
                tools:text="Normal" />

            <TextView
                android:id="@+id/tvBMIDescription"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:textSize="18sp"
                tools:text="Normal" />
        </LinearLayout>

        <Button
            android:id="@+id/btnCalculateUnits"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_marginTop="35dp"
            android:background="@color/colorAccent"
            android:text="CALCULATE"
            android:textColor="#FFFFFF"
            android:textSize="18sp" />
    </LinearLayout>
</RelativeLayout>

and here is styles.xml这里是 styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>

Here is the stacktrace这是堆栈跟踪

2021-04-29 16:49:39.077 5682-5682/? I/nminutesworkou: Not late-enabling -Xcheck:jni (already on)
2021-04-29 16:49:39.090 5682-5682/? I/nminutesworkou: Unquickening 12 vdex files!
2021-04-29 16:49:39.100 5682-5682/? W/nminutesworkou: Unexpected CPU variant for X86 using defaults: x86
2021-04-29 16:49:39.434 5682-5682/com.example.sevenminutesworkout D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2021-04-29 16:49:39.436 5682-5682/com.example.sevenminutesworkout D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2021-04-29 16:49:39.466 5682-5710/com.example.sevenminutesworkout D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2021-04-29 16:49:39.472 5682-5710/com.example.sevenminutesworkout D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2021-04-29 16:49:39.478 5682-5710/com.example.sevenminutesworkout D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2021-04-29 16:49:39.585 5682-5682/com.example.sevenminutesworkout W/nminutesworkou: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-04-29 16:49:39.588 5682-5682/com.example.sevenminutesworkout W/nminutesworkou: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-04-29 16:49:39.655 5682-5708/com.example.sevenminutesworkout D/HostConnection: HostConnection::get() New Host Connection established 0xf6a1f110, tid 5708
2021-04-29 16:49:39.659 5682-5708/com.example.sevenminutesworkout D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2 
2021-04-29 16:49:39.661 5682-5708/com.example.sevenminutesworkout W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2021-04-29 16:49:39.670 5682-5708/com.example.sevenminutesworkout D/EGL_emulation: eglCreateContext: 0xf6a1fb20: maj 2 min 0 rcv 2
2021-04-29 16:49:39.674 5682-5708/com.example.sevenminutesworkout D/EGL_emulation: eglMakeCurrent: 0xf6a1fb20: ver 2 0 (tinfo 0xf6d70170) (first time)
2021-04-29 16:49:39.698 5682-5708/com.example.sevenminutesworkout I/Gralloc4: mapper 4.x is not supported
2021-04-29 16:49:39.700 5682-5708/com.example.sevenminutesworkout D/HostConnection: createUnique: call
2021-04-29 16:49:39.700 5682-5708/com.example.sevenminutesworkout D/HostConnection: HostConnection::get() New Host Connection established 0xf6a1fb90, tid 5708
2021-04-29 16:49:39.722 5682-5708/com.example.sevenminutesworkout D/goldfish-address-space: allocate: Ask for block of size 0x100
2021-04-29 16:49:39.723 5682-5708/com.example.sevenminutesworkout D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3fbcae000 size 0x2000
2021-04-29 16:49:39.728 5682-5708/com.example.sevenminutesworkout D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2 
2021-04-29 16:49:44.812 5682-5682/com.example.sevenminutesworkout D/AndroidRuntime: Shutting down VM
2021-04-29 16:49:44.822 5682-5682/com.example.sevenminutesworkout E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.sevenminutesworkout, PID: 5682
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sevenminutesworkout/com.example.sevenminutesworkout.BMIActivity}: android.view.InflateException: Binary XML file line #67 in com.example.sevenminutesworkout:layout/activity_bmi: Binary XML file line #67 in com.example.sevenminutesworkout:layout/activity_bmi: Error inflating class com.google.android.material.textfield.TextInputLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        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:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: android.view.InflateException: Binary XML file line #67 in com.example.sevenminutesworkout:layout/activity_bmi: Binary XML file line #67 in com.example.sevenminutesworkout:layout/activity_bmi: Error inflating class com.google.android.material.textfield.TextInputLayout
     Caused by: android.view.InflateException: Binary XML file line #67 in com.example.sevenminutesworkout: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:696)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
        at com.example.sevenminutesworkout.BMIActivity.onCreate(BMIActivity.kt:24)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        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:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
2021-04-29 16:49:44.824 5682-5682/com.example.sevenminutesworkout E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     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

I've tried to change AppCompat to MaterialComponents but it doesn't work.我试图将 AppCompat 更改为 MaterialComponents 但它不起作用。 But when I point to LinearLayout tag (parent of com.google.android.material.textfield.TextInputLayout), it shows the error with a red line, and it disappears when I remove LinearLayout tag away.但是当我指向 LinearLayout 标签(com.google.android.material.textfield.TextInputLayout 的父标签)时,它会用红线显示错误,当我删除 LinearLayout 标签时它会消失。 Is there any problem when I use too many LinearLayout stacks up each other?当我使用过多的 LinearLayout 相互堆叠时有什么问题吗?

Did you add material dependency in your app level build.gradle file?您是否在应用程序级别的 build.gradle 文件中添加了材料依赖项?

If not you need to add this in your gradle file.如果不是,您需要在 gradle 文件中添加它。

api 'com.google.android.material:material:<VERSION>'

make sure to add the material dependency in your app level build.gradle file and change the确保在您的应用级别 build.gradle 文件中添加材料依赖项并更改

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

to

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 膨胀错误 class com.google.android.material.textfield.TextInputLayout - Error inflating class com.google.android.material.textfield.TextInputLayout 错误膨胀类 com.google.android.material.textfield.TextInputLayout Android Studio 3.5 - Error inflating class com.google.android.material.textfield.TextInputLayout Android Studio 3.5 二进制 XML 文件第 41 行:膨胀 class com.google.ZC31B32364CE19CA8FCD150A. - Binary XML file line #41: Error inflating class com.google.android.material.textfield.TextInputLayout Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class com.google.android.material.textfield.TextInputLayout - Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class com.google.android.material.textfield.TextInputLayout Binary XML file line #21: Binary XML file line #21: Error inflating class com.google.android.material.textfield.TextInputLayout - Binary XML file line #21: Binary XML file line #21: Error inflating class com.google.android.material.textfield.TextInputLayout 如何正确设置 com.google.android.material.textfield.TextInputLayout 的样式? - How to style com.google.android.material.textfield.TextInputLayout correctly? boxStrokeColor 与 com.google.android.material.textfield.TextInputLayout 不起作用 - boxStrokeColor with com.google.android.material.textfield.TextInputLayout is not work 如何从 com.google.android.material.textfield.TextInputLayout 中删除背景错误红色 - How to remove background error red color from com.google.android.material.textfield.TextInputLayout 如何给 com.google.android.material.textfield.TextInputLayout 提供阴影? - how can i give shadow to the com.google.android.material.textfield.TextInputLayout? 如何修复投射 androidx.appcompat.widget.AppCompatButton 无法投射到 com.google.android.material.textfield.TextInputLayout - How to fix casting androidx.appcompat.widget.AppCompatButton cannot be cast to com.google.android.material.textfield.TextInputLayout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM