Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't find ItemView

1

2

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    var tvName: TextView = itemView.findViewById(R.id.tvName)
    var tvAge: TextView = itemView.findViewById(R.id.tvAge)
    var ivProfile: ItemView = itemView.findViewById(R.id.ivProfile)

    fun bind(contact: Contact) {
        tvName.text = contact.name
        tvAge.text = "Age: ${contact.age}"

        Glide.with(context).load(contact.imageUrl).into (ivProfile)
    }
  }
}

Is there in kotlin only MenuView.ItemView? Because Glide expects ItemView

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Error Log:

Type mismatch: inferred type is MenuView.ItemView but ImageView was expected.

And if I paste instead of MenuView.ItemView ImageView then it says:

java.lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.ImageView
                                                                                                    at com.jakob.kotlinrecyclerview.ContactAdapter$ViewHolder.<init>(ContactAdapter.kt:35)
                                                                                                    at com.jakob.kotlinrecyclerview.ContactAdapter.onCreateViewHolder(ContactAdapter.kt:17)
                                                                                                    at com.jakob.kotlinrecyclerview.ContactAdapter.onCreateViewHolder(ContactAdapter.kt:13)

>Solution :

You should be using ImageView and not ItemView there.

For the ClassCastException check that the layout has id ivProfile for the ImageView only and not e.g. in a higher-level ConstraintLayout.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading