重建后数据绑定错误

DataBinding error after rebuild

在我的应用程序中,我使用的是 DataBinding 实用程序

dataBinding {
    enabled = true
}

一切正常,直到我重建我的项目,然后我收到以下错误消息:

其中几个:

error:(12, 40) error: cannot find symbol class MyClassNameBinding

还有一个大的:

error:Execution failed for task ':app:compileDebugJavaWithJavac'. android.databinding.tool.util.LoggedErrorException: Found data binding errors.

****/ data binding error ****

msg:Cannot find the setter for attribute 'android:src' with parameter type android.graphics.drawable.Drawable on android.widget.ImageView. file:[myPath]\layer_edit_list_item.xml loc:25:27 - 25:209

****\ data binding error **** ****/ data binding error ****

msg:Cannot find the setter for attribute 'android:onClick' with parameter type lambda on android.widget.ImageButton. file:[myPath]\composition_list_item.xml loc:25:31 - 25:73

****\ data binding error **** ****/ data binding error ****

msg:Cannot find the setter for attribute 'android:onClick' with parameter type lambda on android.widget.LinearLayout. file:[myPath]\line_list_item.xml loc:14:27 - 14:59

****\ data binding error **** ****/ data binding error ****

msg:Cannot find the setter for attribute 'android:onClick' with parameter type lambda on android.widget.LinearLayout. file:[myPath]\content.xml loc:50:43 - 50:83

****\ data binding error **** ****/ data binding error ****

msg:Cannot find the setter for attribute 'android:onClick' with parameter type lambda on android.widget.LinearLayout. file:[myPath]\search_list_item.xml loc:14:27 - 14:65

****\ data binding error ****

@Jan 如果忘记在相应布局文件中添加 data 标签,或者在视图中使用模型 class 添加错误的变量,就会出现上述错误.所以请确保所有内容都已正确添加到布局 xml 文件中。并再次重建。如果它仍然存在,则尝试 invalidate/restart 缓存,

我遇到过这个问题。所以我的解决方案是更改为项目视图-> 删除 .Gradle 和 .idea 文件夹-> 重建项目-> 完成