Java android.support.design.widget.TextInputLayout 无法实例化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38423809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:19:23  来源:igfitidea点击:

android.support.design.widget.TextInputLayout could not be instantiated

javaandroidandroid-textinputlayout

提问by SHIDHIN.T.S

I want to integrate android.support.design.widget.TextInputLayoutIn my android application. I have copied the jar file android-support-design.jarfrom the sdk to my applications lib folder. I have added below code in my xml file for the Email EditText,

我想集成android.support.design.widget.TextInputLayout到我的 android 应用程序中。我已将 jar 文件android-support-design.jar从 sdk复制到我的应用程序 lib 文件夹中。我在电子邮件 EditText 的 xml 文件中添加了以下代码,

 <!-- Email Label -->
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="Email" />
        </android.support.design.widget.TextInputLayout>

While add this code in my layout.xml file I am getting an error like,

在我的 layout.xml 文件中添加此代码时,出现如下错误:

Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be instantiated:
- android.support.design.widget.TextInputLayout (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.

How can i fix this issue...

我该如何解决这个问题...

采纳答案by nshmura

If you uses AndroidStudio, you should not include android-support-design.jar. Instead, write like below in your build.gradle:

如果您使用 AndroidStudio,则不应包含 android-support-design.jar。相反,在你的 build.gradle 中像下面这样写:

dependencies {
    ...
    compile 'com.android.support:design:24.0.0'
    ...
}

Edit: If this doesn't work you are probably using a different version. In Windows, go to:

编辑:如果这不起作用,您可能正在使用不同的版本。在 Windows 中,转到:

[android-sdk]\extras\android\m2repository\com\android\support\design

On Mac:

在 Mac 上:

sdk/extras/android/m2repository/com/android/support/design

This directory holds a number of version folders. Use the latest version on your build.gradle.

该目录包含许多版本文件夹。在 build.gradle 上使用最新版本。

回答by Vickie Kangare

You are making mistake in giving id give id to TextInputLayout

你在给 id 给 TextInputLayout 时犯了一个错误

回答by Sai Gopi N

replace

代替

android.support.design.widget.TextInputLayout

with

com.google.android.material.textfield.TextInputLayout

回答by anjali krishnan

I had similar problem, replace the TextInputLayout design pattern with below resolved for me:

我有类似的问题,用下面的解决方案替换 TextInputLayout 设计模式:

com.google.android.material.textfield.TextInputLayout

com.google.android.material.textfield.TextInputLayout

回答by Soumen Das

add in the build.gradle following this line:

在此行后面的 build.gradle 中添加:

implementation 'com.android.support:design:28.0.0'

and use in the xml file:

并在 xml 文件中使用:

 <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/inputLayoutMobile"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/dimen_20dp"
                    android:layout_marginRight="@dimen/dimen_20dp"
                    android:hint="@string/phone_number"
                    android:visibility="gone"
                    android.support.design:layout_constraintTop_toBottomOf="@+id/inputLayoutAppServerUrl">

                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/edtTxtMobile"
                        style="@style/Style_TextView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:drawableLeft="@drawable/ic_smartphone"
                        android:drawablePadding="@dimen/dimen_10dp"
                        android:inputType="number"
                        android:singleLine="true"
                        android:scrollbars="vertical"
                        android:text="@={SettingViewModel.mMobileNo}"
                        android:textSize="@dimen/font_13sp" />
                </com.google.android.material.textfield.TextInputLayout>

回答by Peter Wauyo

The dependency your using is part of the Android support library which is now deprecated and no longer supported by Google. Instead, use this:
implementation 'com.google.android.material:material:<version>'
and replace <version>with the latest version from either Google's Maven Repositoryor MVN Repository

您使用的依赖项是 Android 支持库的一部分,该库现已弃用且不再受 Google 支持。相反,使用这个:
implementation 'com.google.android.material:material:<version>'
并替换<version>为来自Google 的 Maven 存储库MVN 存储库的最新版本

Perhaps you could read more from here Getting Started

也许你可以从这里开始阅读更多