【问题标题】:android.support.design.widget.TextInputLayout failed to instantiateandroid.support.design.widget.TextInputLayout 无法实例化
【发布时间】:2016-02-29 15:24:54
【问题描述】:

尝试在 android 中使用 TextInputLayout 时出现错误

我有 android 支持库版本 23。但仍然出现错误

我的 xml 文件显示错误是

以下类无法实例化:

- android.support.design.widget.TextInputLayout (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.


11-25 00:58:30.967: E/AndroidRuntime(27848): Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
11-25 00:58:30.967: E/AndroidRuntime(27848):    at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:34)
11-25 00:58:30.967: E/AndroidRuntime(27848):    at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:103)
11-25 00:58:30.967: E/AndroidRuntime(27848):    at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:96)
11-25 00:58:30.967: E/AndroidRuntime(27848):    ... 24 more


11-25 13:32:29.967: E/AndroidRuntime(18136): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.TextInputLayout" on path: DexPathList[[zip file "/data/app/com.odibly.android-1/base.apk"],nativeLibraryDirectories=[/data/app/com.odibly.android-1/lib/arm, /vendor/lib, /system/lib]]

11-25 13:32:29.967: E/AndroidRuntime(18136):    Suppressed: java.lang.ClassNotFoundException: android.support.design.widget.TextInputLayout

【问题讨论】:

  • 您是否已将该库添加到您的项目中?

标签: android-layout material-design


【解决方案1】:

需要在gradle文件中添加这个依赖

compile 'com.android.support:design:23.1.1'

【讨论】:

  • 我使用的是 Eclips 而不是 android studio
  • @KomalNikhare 那么您需要将该库从..../sdk/extras/android/support/design 添加到您的项目中。
  • 我已经将此库添加到我的项目中,所有设置都已完成,但仍然显示错误..
  • 通过更改 AppCompact 主题来解决这些错误...谢谢@NigamPatro 我在印度工作
【解决方案2】:

当然,您需要在位于/app 内的build.gradle 文件中添加依赖项

dependencies {
    ...
    implementation 'com.android.support:design:27.0.1' //change compile to implementation
    ...
    }
}

但如果你还在使用 Eclipse,使用支持库可能会遇到一些问题,我建议开始使用 Android Studio。

The Eclipse ADT plugin is no longer supported per our announcement. Android Studio 现在是 Android 的官方 IDE,所以你应该 尽快将您的项目迁移到 Android Studio。更多 有关过渡到 Android Studio 的信息,请参阅迁移到 Android 来自 Eclipse 的工作室。

【讨论】:

    【解决方案3】:

    您需要将以下内容添加到您的模块build.gradle 文件中:

    implementation 'com.google.android.material:material:1.0.0'
    

    并在您的 XML 中使用 com.google.android.material.textfield.TextInputLayout

       <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/text_input_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/my_hint">
    

    【讨论】:

    • 这行得通。但为什么?一个罐子装在另一个罐子里?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 2016-06-09
    • 2020-10-26
    • 2016-11-22
    • 2017-01-29
    相关资源
    最近更新 更多