ViewHolder with onClicklistener Issue with UninitializedPropertyAccessException

I’m a beginner so please bare with me.

I have a viewholder that has an onclicklistener.

The aim of the click is to send a Url string into another fragment using Jetpack Navigation (hopefully i did it right)

the Url is being created within the dataclass itself.

but i keep getting this error:

kotlin.UninitializedPropertyAccessException: lateinit property galleryItem has not been initialized

I tried working around using companion object and other ways, nothing worked… is there a solution for this?

here is the view holder and data class

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import androidx.core.os.bundleOf
import androidx.navigation.Navigation
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide

class RecyclerViewPhotoAdapter() :
    PagingDataAdapter<PagingData.GalleryItem, PhotoHolder>(
        diffCallback = DiffCallback
    ) {
    override fun onBindViewHolder(holder: PhotoHolder, position: Int) {
        getItem(position)?.let {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PhotoHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.photo_item_view,parent,false)
        return PhotoHolder(view)

class PhotoHolder(view: View):
    RecyclerView.ViewHolder(view), View.OnClickListener {
    private val imageButtom: ImageButton = view.findViewById(
    private lateinit var galleryItem: PagingData.GalleryItem //page. 594

    fun bind(galleryItem : PagingData.GalleryItem){
        idTextView.text =
        ownerTextView.text = galleryItem.owner
        titleTextView.text = galleryItem.title
        urlTextView.text = galleryItem.url
        galleryItem.url.let { url ->

    init {

    override fun onClick(v: View?) {
        println("item was clicked")
        val bundle = bundleOf("url" to galleryItem.photoPageUri )  <-- here is the issue

object DiffCallback : DiffUtil.ItemCallback<PagingData.GalleryItem>() {

    override fun areItemsTheSame(oldItem: PagingData.GalleryItem, newItem: PagingData.GalleryItem): Boolean {
        // Id is unique.
        return ==

    override fun areContentsTheSame(oldItem: PagingData.GalleryItem, newItem: PagingData.GalleryItem): Boolean {
        return oldItem == newItem

data class

import androidx.annotation.Keep

data class PagingData(
    val total : Int =0,
    val Page: Int = 0,
    val photos : List<GalleryItem>
    val endOfPage = total == Page

    data class GalleryItem(
        val id: String,
        val owner: String,
        var title: String,
        val url: String) {
        val photoPageUri : Uri <-- here is the value
            get() {
                return Uri.parse("")


As the error states, you haven’t initialised the galleryItem instance variable in your PhotoHolder. Add this inside your bind method:

this.galleryItem = galleryItem