Konstantin Konopko
Konstantin Konopko

Reputation: 5422

Android Studio Binding error Cannot resolve method

Android Studio 3.1.3 informs that cannot resolve method error while trying call Data Binding method. Data binding is enabled in build.gradle. Clear and/or Rebuild project takes no effect. Only one thing helps — restarting Android Studio. Any suggestions?

An interesting moment is that Studio can build and run the app, inspite of the data binding error.

Upvotes: 1

Views: 1011

Answers (2)

Konstantin Konopko
Konstantin Konopko

Reputation: 5422

It seems to this is known bug of AS. You can solve this by the following:

  1. Rename corresponding layout file (Ctrl+F6)
  2. Run Rebuild project (errors will shown as a result)
  3. Rename the layout back to original name

This works for me.

Upvotes: 1

Kamarudeen Ayankunbi
Kamarudeen Ayankunbi

Reputation: 427

When you build and deploy to your device, Data Binding will generate an associated class with a similar name, just in CamelCase: ListItemCrimeBinding.

Unlike generated code tools like Dagger, Data Binding does not rely on generated code for type checking. Instead, it is integrated into Android Studio, so that you do not have to wait through a whole code generation pass to use the fields and methods Data Binding provides.

As of this writing, this integration needs a little jump-start to get going. To make ListItemCrimeBinding available after adding the tag, you must restart Android Studio, then rebuild the project.

https://www.bignerdranch.com/blog/descent-into-databinding/.

Upvotes: 0

Related Questions