【问题标题】:Android Error inflating class TextInputLayoutAndroid错误膨胀类TextInputLayout
【发布时间】:2015-08-17 08:45:19
【问题描述】:

我正在尝试在我的 XML 中使用 TextInputLayout,但遇到了这个错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.jechange.moncompte/fr.jechange.moncompte.SignUpActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.design.widget.TextInputLayout
[...]
Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.design.widget.TextInputLayout
[...]
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/design/R$styleable;

我已经导入了设计库和support-v7-appcompat 库。我正在使用Theme.AppCompat.Light.NoActionBar 主题。

我在其中使用 文本输入布局 的 XML 包含类似的内容:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:res="http://schemas.android.com/apk/res-auto"
style="@style/matchParent">

    <android.support.design.widget.TextInputLayout
        android:id="@+id/input"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:inputType="text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>
</RelativeLayout>

【问题讨论】:

  • 确保您的 lib 文件夹中有 v7 jar 文件。
  • 我试过但没有。但是目前,我将我的项目与 support-v7-appcompat 库相关联,所以我不需要添加 v7 jar 吗? (我一直对库、jar 等有疑问)
  • 当我们链接一个 lib 时,它会自动添加到 lib 目录中,但有时它不会。所以我们必须手动完成。
  • 好的,所以在我的情况下,v7 jar 没有添加到我的项目中。但是我手动添加了它,并没有解决我的问题:/
  • 您使用的是哪个 IDE?

标签: android android-design-library


【解决方案1】:

如果您从活动中调用布局(包含 TextInputLayout),那么 没有什么只是使用 YouActivityClassName.this 代替 getApplicationcontext 或 YourApplicationClassName.getcontext() 或其他您传递上下文的地方

【讨论】:

    【解决方案2】:

    我解决了同样的问题here。 确保您没有任何其他支持库导入 v4 和 v7。您只能使用设计支持库。此外,您应该确保您的主题“matchParent”从您尝试运行的所有平台的 Theme.AppCompat 继承。 由于values-21/style.xml,我的问题只出现在棒棒糖上。

    希望它会有所帮助。

    【讨论】:

    • 不,很好...由于其他原因重启了几次eclipse后,它可以工作...大声笑...
    • 我的风格继承Theme.AppCompat.Light.NoActionBar希望没问题
    猜你喜欢
    • 1970-01-01
    • 2017-09-08
    • 2021-04-09
    • 2016-11-12
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多