Identifiers must have user defined types from the XML file. View is missing it

本文记录了一次关于Android Data Binding的常见错误处理过程,包括如何正确使用@Bindable注解及解决XML文件中类型引用的问题。



一次粗心大意的记录,大家引以为戒。

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


其实官方文档上写的很清楚,只是自己太粗心大意,我未太在意,所以自己跳坑是正常的,不仅仅因为英语水平太一般,更是自己没有
耐心把文档好好读上几遍。对读几遍。读几遍。几遍。遍





If 'Example.java' is a standalone Java file that is not part of any project structure, and it contains only syntax errors, you can expect to see compiler-generated error messages. These messages will typically indicate issues with the code's compliance with the Java language specification. Here are some common error messages you might encounter: 1. **SyntaxError**: This is the most basic error indicating a problem with the syntax, such as missing semicolons, unmatched brackets, or incorrect use of keywords. ``` Example.java:1: error: ';' expected // Incorrect line here ^ ``` 2. **MissingTypeDeclaration**: If a class, interface, or variable declaration is incomplete, you'll get an error for this. ``` Example.java:5: error: class, interface, or enum expected method(); // Missing 'class' keyword or '{' ^ ``` 3. **InvalidVariableName**: Names used in identifiers must follow certain rules (e.g., cannot start with numbers). ``` Example.java:7: error: illegal name int$3 = 0; // Invalid because '$' is not allowed as a first character ^ ``` 4. **UnresolvedReferences**: If you reference a class or method that hasn't been imported or defined, you'll get an error like this. ``` Example.java:10: error: cannot find symbol MyClass myObject; // Error since MyClass is not declared ^ ``` 5. **RedefinedIdentifier**: If a variable, class, or import is accidentally redefined within the same scope, you'll receive an error. ``` Example.java:15: error: already assigned to int x = 5; // First assignment x = 10; // Second assignment, generates error ``` To resolve these errors, carefully review the highlighted lines in the compiler output and fix the syntax issues according to the Java Language Specification. Make sure to adhere to proper indentation, curly braces, and correct usage of language constructs.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值