问题描述
报错:
e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors.
****/ data binding error ****msg:Identifiers must have user defined types from the XML file. View is missing it
file:D:\Android\MyApplication\***\***\***\app\src\main\res\layout\activity_***.xml
loc:28:60 - 28:63
loc:28:75 - 28:78
****\ data binding error ****
对应代码:
<Button
android:id="@+id/btn_front"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="@drawable/ic_close"
android:visibility="@{model.show ? View.VISIBLE : View.GONE}" />
解决方案
参考:https://blog.csdn.net/qq_35599978/article/details/80093768
方式一:
其实这个bug很简单就是忘记在xml 中导入android.view.View包了,导入就好了
代码:
<data>
<import type="android.view.View" /> // 导入View包
<variable
name="model"
type="pro.***.***.ItemViewModel" />
</data>