我正在解决错误 "Cannot find a setter ..."

I'm on trouble to solve the error "Cannot find a setter ..."

这是错误信息。

Cannot find a setter for <xxx.xxx.xxx.view.customview.ImageView resource> that accepts parameter type 'java.lang.String'

我在布局文件上使用这个自定义视图

layoutA.xml

<xxx.xxx.xxx.view.customview.ImageView
resource="@{data.imageUrl}"

数据class 如下图。我要为 imageUrl

添加图像 URL
data class Design(
    val imageUrl: String?
)

如何解决这个构建错误?

谢谢大家的回答。我解决了这个问题。我有绑定适配器 class,它的类型需要 Int?。换句话说,resource 期待 Int 所以我只需要将类型 Int? 更改为 String。 以下代码在下方

之前

    @JvmStatic
    @BindingAdapter("resource")
    fun ImageView.bindResource(id: Int?) {
       //do something
    }

之后

    @JvmStatic
    @BindingAdapter("resource")
    fun ImageView.bindResource(id: String?) // Just changed type
     {
       //do something
    }