安卓数据绑定(bind): how to get useful error messages

标签 android android-databinding

在 android studio 2.1 中,来自 xml 错误的编译时错误消息完全没有帮助:

Error:(11, 41) error: package mypackage.databinding does not exist
Error:(15, 13) error: cannot find symbol class MyActivityBinding

真正的错误通常是“没有这样的属性 android:adapter”,或者“变量 foo 不包含属性栏”或类似的东西。但它并没有实际显示此类错误,而是显示了上述无用的错误,这些错误只会告诉您由于某些未知错误而未生成绑定(bind)。

最佳答案

我在 Android Studio 4.0 中的使用方式:

  1. 选择 Build Output 面板上的顶级 Build: failed

    Failed build output panel

  2. 在右侧点击Run with --stacktrace。构建完成后,再次在左侧面板上选择顶部的 Build: failed 项。您将在右侧面板上看到数据绑定(bind)错误说明:

    enter image description here 在我的情况下是:

    [databinding] {"msg":"Cannot find a getter for \u003ccom.google.android.material.slider.Slider app:value\u003e that accepts parameter type \u0027java.lang.Float\u0027\n\nIf a binding adapter provides the getter, check that the adapter is annotated correctly and that the parameter type matches.","file":"SliderDatabinding\src\main\res\layout\activity_main.xml","pos":[{"line0":14,"col0":8,"line1":21,"col1":41}]}

关于安卓数据绑定(bind): how to get useful error messages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37113416/

相关文章:

android - 当宽度设置为 match_parent 时,GridLayout 第二列内的 LinearLayout 会溢出屏幕

java - 以编程方式创建 map View

android - Two-way databinding(in xml), ObservableField, BaseObservable ,我应该使用哪一个来进行双向数据绑定(bind)?

android - 数据绑定(bind)传递带有特殊字符的 xml 元素

Android 数据绑定(bind) @{} 与 @={}

android - 如何在 Activity 的父 Activity 被销毁时保持 Activity 存活

android - Google Maps API 获取 JSON 数据并将其设置为信息窗口

java - 从 RecyclerView 项目启动 ViewPager

android - 在android上覆盖布局和数据绑定(bind)生成的类

android - 我应该如何在 Android 的 viewModel 中获取 Resources(R.string)(MVVM 和数据绑定(bind))