Search code examples
androidkotlinandroid-databinding

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


This is the error message.

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

I use this customview on the layout file

layoutA.xml

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

data class is like down below. I'm going to add image URL for imageUrl

data class Design(
    val imageUrl: String?
)

How can I solve this build error?


Solution

  • Thank you everyone for the answer. I solved this problem. I have Binding adapter class and its type was expecting Int?. In other words, resource is expecting Int so I just need to change type Int? to String. Following code was down below

    Before

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

    After

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