androidkotlinandroid-livedataandroid-pagedlistview

Error: "Type mismatch. Required: Observer<PagedList<MyItem!>!>". How to fix?


I'm using PagedListAdapter and pagedListLiveData without Room to display a large list of items.
In code below i'm trying to submit adapter to PagedList.

val pagedListLiveData = LivePagedListBuilder(sourceFactory, pagedListConfig)
       .setFetchExecutor(Executors.newSingleThreadExecutor())
       .build()

val adapter = MyPagedAdapter()

// error below: Type mismatch. Required:Observer<PagedList<MyItem!>!>
pagedListLiveData.observe(lifeCycleOwner, object : Observer<PagedList<MyItem>>() {
        override fun onChanged(items: PagedList<MyItem>) {
            Log.d(LOG_TAG, "submit PagedList")
            adapter.submitList(items)
        }
})

Android Studio highlights an error on the expression:

object : Observer<PagedList<MyItem>>

Error: Type mismatch. Required: Observer<PagedList<MyItem!>!>

How to fix it?


Solution

  • Thanks to Kingfisher Phuoc and Jeel Vankhede. Problem was in importing Observer. This code works fine:

    pagedListLiveData.observe(lifeCycleOwner, android.arch.lifecycle.Observer{
        adapter.submitList(it)
    })