安卓XML:"与另一个具有相同ID的标签冲突"。

25

最近我从我的项目中删除了一个包括其布局和视图模型的片段 (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清理了这个项目。我尝试使用相同的菜单重新构建项目。但结果仍然是一样的。

有人有解决这个问题的想法吗?


你解决了这个问题吗? - Trung Bui
14个回答

51

这些文件是在编译时创建的,因此可能尚未被删除。尝试在Android Studio中使缓存失效并重新启动。


不起作用... - philoopher97

6
如果您使用视图绑定,可以将以下内容添加到布局中,直到您拥有更好的视图ID:
tools:viewBindingIgnore="true"

为每个出现问题的布局执行此操作。

我从这里找到了这个技巧。


4
有时候,“无效缓存/重启”选项无法正常工作。
gradlew assembleDebug

只需尝试运行此命令,然后问题将不再存在。


3
如果文件 > 使缓存无效/重新启动 > 使无效并重启不能解决你的问题,也许你可以尝试:
  1. 删除
    buildFeatures {
        dataBinding =  true
    }
  1. 使无效
  2. 关闭AndroidStudio
  3. 如果您的系统是Windows,请打开资源监视器(因为我的电脑是中文系统,所以我不知道如何在英文系统中翻译这个单词)。打开命令提示符,输入perfmon,然后就可以看到它了。
  4. 点击CPU->相关句柄->搜索android。
  5. 关闭所有相关句柄,然后打开AndroidStudio并添加
    buildFeatures {
        dataBinding =  true
    }

enter image description here

enter image description here

enter image description here


3

关于如何使缓存失效,你可以在Android Studio中执行以下操作:转到文件菜单(File) > 点击无效化缓存/重启(Invalidate Caches / Restart) > 点击“无效化并重启”(Invalidate and Restart)


1
在我的情况下,XML文件中有相同的ID分配给不同的视图。我只是改变了其中一个以避免冲突,然后它就起作用了。

1
有时以上解释的任何技巧都不像预期的那样有效。清除缓存并重启 Android Studio 对我根本没有用。我也尝试了以下命令。
gradlew assembleDebug

但这只能起到一次作用。每次更改布局文件时,我都必须这样做。如果上述方法都不起作用,请尝试以下技巧:
  • 重命名布局文件。您可能还想更改绑定类
  • 将项目导出为zip文件,在不同的位置解压缩并打开现有项目。

0

如果你遇到这样的问题,请按照以下步骤操作:

如果你的系统是Windows,

  1. 打开cmd,输入perfmon,然后你会看到它。
  2. 点击“打开资源监视器”选项
  3. 点击CPU->相关句柄->搜索android。
  4. 关闭所有相关句柄,然后打开你的AndroidStudio

现在你会发现没有这样的错误了。这个过程对我有效。


0

可能出现这样的情况,您不小心创建了一个layout-26文件夹,在其中有两个同名的XML文件。

解决方案:

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

2.删除layout-26文件夹。


0
有时候在当前文件中重构(重命名)id并更改整个项目中的id会导致此问题出现。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接