Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android data binding: how to get useful error messages

Tags:

In android studio 2.1, the compile time error messages from xml mistakes are entirely non-helpful:

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

The real error would usually be something like "there's no such attribute android:adapter", or "variable foo doesn't contain property bar" or something like that. But instead of actually showing such errors, it shows the above unhelpful ones, which only tell you that the bindings weren't generated because of some unknown error.

like image 799
urandom Avatar asked May 09 '16 10:05

urandom


People also ask

How check data binding is null in Android?

If you want to check for null and empty, it's better to use TextUtils. isEmpty instead.

Is data binding deprecated Android?

Kotlin Android Extensions is deprecated, which means that using Kotlin synthetics for view binding is no longer supported.


1 Answers

The way I use in Android Studio 4.0:

  1. Select the top level Build: failed item on the Build Output panel

    Failed build output panel

  2. On the right part click Run with --stacktrace. When build is finished select the top Build: failed item again on the left panel. You'll get a databinding error description on the right panel:

    enter image description here In my case it's:

    [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}]}

like image 161
Valeriy Katkov Avatar answered Sep 21 '22 17:09

Valeriy Katkov