Android XML:“与另一个具有相同ID的标签冲突”

时间:2019-09-08 10:44:08

标签: android xml android-studio android-layout android-xml

我最近从我的项目中删除了一个片段,包括其布局和视图模型。 (FragmentAddFlight,VmAddFlight,fragment_add_flight.xml)

令人惊讶的是,我得到了这些错误:

    [databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":277,"col0":20,"line1":286,"col1":85}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":308,"col0":28,"line1":312,"col1":64}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":314,"col0":28,"line1":318,"col1":60}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":327,"col0":28,"line1":331,"col1":63}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":333,"col0":28,"line1":338,"col1":57}]}
  [databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":369,"col0":20,"line1":378,"col1":72}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":400,"col0":28,"line1":404,"col1":60}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":406,"col0":28,"line1":410,"col1":60}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":419,"col0":28,"line1":423,"col1":71}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":425,"col0":28,"line1":430,"col1":57}]}
  [databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":452,"col0":20,"line1":461,"col1":77}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":483,"col0":28,"line1":487,"col1":60}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":489,"col0":28,"line1":493,"col1":60}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":502,"col0":28,"line1":506,"col1":71}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":508,"col0":28,"line1":513,"col1":57}]}

请记住,这些错误中引用的文件已被删除。为什么会出现这些错误?

我通过Build-> clean project清理了项目。我试图通过相同的菜单重建项目。但是结果保持不变。

有人知道如何解决此问题吗?

9 个答案:

答案 0 :(得分:6)

这些文件是在编译时创建的,因此它们可能尚未删除,请尝试使缓存无效并在android studio中重新启动。

答案 1 :(得分:3)

要添加有关如何使缓存无效的信息,请在Android Studio中转到“文件”>“使缓存无效/重新启动”>“使并重新启动”

答案 2 :(得分:2)

pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" title="Please enter a valid email address" 选项有时不起作用。

Invalidate Caches/Restart

只需尝试此命令,然后查看问题将不再可用。

答案 3 :(得分:1)

如果使用视图绑定,则可以将其添加到布局中,直到获得更好的视图ID:

{{1}}

针对每个有问题的布局执行此操作。

我从这里找到了这个提示:

https://proandroiddev.com/new-in-android-viewbindings-the-difference-from-databinding-library-bef5945baf5e

答案 4 :(得分:0)

编译时间问题: 固定: 1.清理项目。 2.清除缓存并重新启动。

确保启用了视图绑定。

答案 5 :(得分:0)

可能是你不小心创建了一个 layout-26 文件夹,里面有两个同名的 XML 文件。

解决方案-:

1.将正确的XML文件从layout-26文件夹移动到layout文件夹

2.删除layout-26文件夹。

答案 6 :(得分:0)

有时上面解释的技巧都没有按预期工作。 Invalidate Cache and Restart Android Studio 根本不适合我。我也尝试了以下命令

gradlew assembleDebug

但它只能工作一次。每次更改布局文件时,我都必须这样做。如果这些技巧都不适合您,请尝试遵循这些技巧

  • 重命名布局文件。您可能还想更改 Binding 类
  • 将项目导出为 zip,将其解压缩到不同位置并打开现有项目。

答案 7 :(得分:0)

以上都不适合我:tools:viewBindingIgnore="true" , invalidate caches, gradlew assembleDebug。一切都行不通。

我发现的唯一方法是删除整个项目并再次从 git 中提取源代码。然后build->正常运行

答案 8 :(得分:0)

如果 ['name6'] 无法解决您的问题。也许你可以试试

  1. 删除
File > Invalidate Caches / Restart > Invalidate and Restart
  1. 无效
  2. 关闭 AndroidStudio
  3. 如果你的系统是 buildFeatures { dataBinding = true } ,打开Windows(因为我的电脑是中文的,所以不知道英文系统怎么翻译这个词。打开resource monitor,输入cmd,你就会看到。)
  4. 点击perfmon->CPU->搜索Associated handle
  5. 关闭所有关联的句柄,然后打开您的 AndroidStudio 并添加
android

enter image description here

enter image description here

enter image description here