com.airbnb.epoxy.IllegalEpoxyUsage: You must set an id on a model before adding it

1.3k Views Asked by At

Using Epoxy Library first time. Getting bellow error

rocess: in.droom, PID: 25269
com.airbnb.epoxy.IllegalEpoxyUsage: You must set an id on a model before adding it. Use the @AutoModel annotation if you want an id to be automatically generated for you.

Here is the controller code:

   class MyMatchesController : EpoxyController() {
    override fun buildModels() {
        for (i in 0 until 10) {
            fillBestMatchesNotification {
                id(i)
                bestMatchesCount("100")
            }
        }
    }
}

Here is the Model code

    @EpoxyModelClass(layout = R.layout.fill_best_match_notification_layout)
abstract class FillBestMatchesFormNotificationModel : EpoxyModelWithHolder<FillBestMatchesFormNotificationModel.ViewHolder>() {

    @EpoxyAttribute
    var id: Long = 0

    @EpoxyAttribute
    var bestMatchesCount = ""


    override fun getDefaultLayout() = R.layout.fill_best_matches_notification_layout

    @CallSuper
    override fun bind(holder: ViewHolder) {
        super.bind(holder)
        holder.countTV.text = bestMatchesCount
    }

    override fun createNewHolder(): ViewHolder {
        return ViewHolder()
    }

    inner class ViewHolder : EpoxyHolder() {
        lateinit var countTV: TextView
        override fun bindView(itemView: View) {
            countTV = itemView.findViewById(R.id.matchedCountNotificationTV)
        }

    }
}

I have tried to delete the id from the Model class but still same error.

1

There are 1 best solutions below

0
On

id is a reserved attribute and must not be declared as a new field with @EpoxyAttribute.

Just define your required attributes. id setters (with different overloads) will generate automatically.

so remove the below lines. everything will work well.

@EpoxyAttribute
var id: Long = 0