23

我最近从我的项目中删除了一个片段,包括它的布局和视图模型。(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 清理了项目。我试图通过相同的菜单重建项目。但结果还是一样。

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

4

10 回答 10

51

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

于 2019-09-08T10:48:00.340 回答
4

Invalidate Caches/Restart选项有时不起作用。

gradlew assembleDebug

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

于 2020-09-05T16:01:53.420 回答
3

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

tools:viewBindingIgnore="true"

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

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

于 2020-11-22T10:07:42.053 回答
3

要添加如何使缓存失效,在 Android Studio 中,转到 File > Invalidate Caches / Restart > Invalidate and Restart

于 2020-04-25T21:10:01.460 回答
1

有时,上面解释的所有技巧都没有按预期工作。使缓存无效并重新启动 Android Studio 根本不适合我。我也尝试了以下命令

gradlew assembleDebug

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

  • 重命名布局文件。您可能还想更改 Binding 类
  • 将项目导出为 zip,将其解压缩到不同的位置并打开现有项目。
于 2021-07-02T10:30:34.007 回答
1

如果File > Invalidate Caches / Restart > Invalidate and Restart不能解决您的问题。也许你可以尝试

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

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

于 2021-08-04T06:18:53.720 回答
0

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

解决方案-:

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

2.删除layout-26文件夹。

于 2021-02-08T16:53:39.840 回答
0

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

确保启用了视图绑定。

于 2020-09-10T20:04:31.477 回答
0

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

于 2021-10-28T11:31:35.007 回答
-1

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

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

于 2021-07-07T05:08:40.450 回答