一次粗心大意的记录,大家引以为戒。
Error:Execution failed for task ':compileDebugJavaWithJavac'.
> 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:\AKE\workspace\NB_BToI\src\main\res\layout\activity_device_new.xml
loc:112:65 - 112:68
loc:112:77 - 112:80
****\ data binding error ****
xml中代码如下
<LinearLayout
android:id="@+id/ll_fold"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|start"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="@{scanbean.isHidExpend ? View.GONE : View.VISIBLE}">
其实明明知道是visibility这行代码出问题了,可就是不知道是啥问题。找了很多资料才发现
其实这个bug很简单就是忘记在xml 中导入android.view.View包了,导入就好了,但是我又绕了一圈,
在scanbean中写了个方法isHidExpend()
获取这个值,我运算符运行不成功,就换个方式
public class ScanBindBean extends BaseObservable {
/** 左上角搜索状态 */
@Bindable
public String scanStatus="正在搜索";
/** 是否显示ll_expend layout*/
@Bindable
public boolean isHidExpend = true;
@Bindable
public String appName="物联网表蓝牙调试工具";
@Bindable
public String version="v2.0";
/** 搜索开关 */
@Bindable
public String scanSwitch="停止";
@Bindable
public String isHidExpend() {
return isHidExpend ? "gone" : "visible";
}
结果又报了这个错,说我javabean中Bindable的方法isHidExpend未遵守约定,给我弄的一脸懵逼,
我去掉了bianable,就好了
@Bindable associated with method must follow JavaBeans convention isHidExpend()错误: @Bindable associated with method must follow JavaBeans convention isHidExpend()
注: wrote intermediate bindable file com.gprs.blue -br.bin
注: ************* Generating BR file com.gprs.blue. use final: APPLICATION
注: writing file com.gprs.blue.BR
注: writing file com.android.databinding.library.baseAdapters.BR
注: writing file android.databinding.DataBinderMapper
其实官方文档上写的很清楚,只是自己太粗心大意,我未太在意,所以自己跳坑是正常的,不仅仅因为英语水平太一般,更是自己没有
耐心把文档好好读上几遍。对读几遍。读几遍。几遍。遍