Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this BindingAdapter not working in Kotlin?

I have a ViewModel with:

val imageUrl = ObservableField<String>()

My layout XML has:

<ImageView
    ...
    app:url="@{viewModel.imageUrl}"
    .../>

I have a BindingAdapters file with a top level function:

@BindingAdapter("url")
fun loadImage(view: ImageView, url: String?) {
    ...
}

I'm getting the following error:

data binding error msg:Cannot find the setter for attribute 'app:url' with parameter type android.databinding.ObservableField<java.lang.String> on android.widget.ImageView.

Any idea why this would be? This is pretty much identical to how I set up binding adapters in Java, minus the static function.

like image 488
SilentByte Avatar asked Oct 04 '18 21:10

SilentByte


Video Answer


1 Answers

This issue was caused by a lack of kapt in the app's build.gradle. Adding the below to build.gradle and replacing all "annotationProcessor" dependencies with "kapt" fixes the issue.

apply plugin: 'kotlin-kapt'
like image 136
SilentByte Avatar answered Oct 02 '22 15:10

SilentByte