在 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 中的使用方式:
选择
Build Output
面板上的顶级Build: failed
项在右侧点击
Run with --stacktrace
。构建完成后,再次在左侧面板上选择顶部的Build: failed
项。您将在右侧面板上看到数据绑定(bind)错误说明:[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/