【问题标题】:Android TextView: Conflict with another tag that has the same IDAndroid TextView:与另一个具有相同 ID 的标签冲突
【发布时间】:2020-08-25 18:41:55
【问题描述】:

我对 Android XML 文件有疑问,需要您的帮助。我有以下代码:

 <TextView
        android:id="@+id/textViewA"
        android:layout_width="95dp"
        android:layout_height="35dp"
        android:text="A"
        android:textColor="#000000"
        android:textSize="22dp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.012"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.671" />

    <TextView
        android:id="@+id/textViewS"
        android:layout_width="95dp"
        android:layout_height="35dp"
        android:text="S"
        android:textColor="#000000"
        android:textSize="22dp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.012"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.584" />

所以基本上我有两个 TextView。编译时,我收到错误消息:

'<TextView id='@+id/textView'> conflicts with another tag that has the same ID'

当我单击错误的相应行时,会显示这两个 TextView。我不太明白这一点,因为他们没有相同的 ID。他们曾经有相同的ID,但我改变了它,仍然出现问题。也许这与我刚刚启用的 ViewBinding 有关?我会很感激每一条评论。

更新:我意识到这实际上与 ViewBinding 有关系,因为我也可以看到以下信息:

Found data binding error(s):

[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\T.D\\AndroidStudioProjects\\BarApp\\BarApp_Projekt\\app\\src\\main\\res\\layout\\activity_cocktail_ytest.xml","pos":[{"line0":48,"col0":4,"line1":61,"col1":52}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\T.D\\AndroidStudioProjects\\BarApp\\BarApp_Projekt\\app\\src\\main\\res\\layout\\activity_cocktail_ytest.xml","pos":[{"line0":121,"col0":4,"line1":134,"col1":52}]}

但我仍然不知道错误的原因。我的意思是他们肯定没有相同的 ID。

【问题讨论】:

  • 你能添加你的activity_cocktail_ytest xml吗?
  • 感谢阿卜杜勒的评论。基本上上面的代码来自 XML 布局文件 'activity_cocktail_ytest xml'
  • 你试过使缓存失效吗?
  • 用于数据绑定android studio自动生成文件。有时使用缓存中的文件不是最新的。因此,当您使缓存无效时,这些文件会在构建时再次生成。
  • 这取决于但通常当您遇到数据绑定问题并且您认为一切都很好时,无效缓存是一个不错的选择。

标签: android xml textview android-viewbinding


【解决方案1】:

使缓存无效并重新启动 android studio 将对您有所帮助。

【讨论】:

    【解决方案2】:

    清理你的项目,然后重建

    【讨论】:

    • 感谢 Reham 的回答。基本上这并没有解决问题。但是,使缓存无效(虽然我不明白为什么)
    【解决方案3】:

    https://stackoverflow.com/a/68280374/6386888

    删除您的项目并再次从 git 中提取源代码。 它可能会有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-09
      • 1970-01-01
      • 2014-01-22
      • 2022-11-15
      • 1970-01-01
      • 1970-01-01
      • 2014-11-13
      相关资源
      最近更新 更多