【问题标题】:incompatible types: AppBarMainBinding cannot be converted to View failure to complile不兼容的类型:AppBarMainBinding 无法转换为 View 无法编译
【发布时间】:2021-05-06 16:11:49
【问题描述】:

我有一个嵌套的包含布局,我尝试在其中传递数据绑定。 以下代码失败并出现以下错误;

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/appBarMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>

    <include
        layout="@layout/content_main"
        android:id="@+id/contentMain"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

/.../ap_generated_sources/debug/out/com/example/.../databinding/ActivityMainBindingImpl.java:35:错误:不兼容的类型:AppBarMainBinding 无法转换为 View , (com.example...databinding.AppBarMainBinding) 绑定[1] ^

如果我删除布局,代码会编译,但添加到包含的 app:params 将不起作用。我错过了什么?怎么修?谢谢

【问题讨论】:

    标签: android kotlin data-binding


    【解决方案1】:

    我遇到了同样的问题,删除app目录下的build文件夹后解决了,再次build没有任何错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-10
      • 2017-10-03
      • 2021-12-20
      • 2016-10-17
      • 1970-01-01
      相关资源
      最近更新 更多