为什么此BindingAdapter在Kotlin中不起作用? [英] Why is this BindingAdapter not working in Kotlin?

查看:792
本文介绍了为什么此BindingAdapter在Kotlin中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ViewModel:

I have a ViewModel with:

val imageUrl = ObservableField<String>()

我的布局XML具有:

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

我有一个具有顶级功能的BindingAdapters文件:

I have a BindingAdapters file with a top level function:

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

我遇到以下错误:

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.

有人知道为什么会这样吗?这与我在Java中设置绑定适配器的方式几乎相同,只不过是静态函数.

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

推荐答案

此问题是由应用程序的build.gradle中缺少kapt引起的.将以下内容添加到build.gradle中,并将所有"annotationProcessor"依赖项替换为"kapt"即可解决此问题.

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'

这篇关于为什么此BindingAdapter在Kotlin中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆