Android paging library java.lang.IllegalArgumentException: MainThreadExecutor required

Viewed 1201

I'm using Android paging library androidx.paging:paging-runtime:2.0.0 to build a list. The problem is that when I want to build PagedList (LivePagedList works well) i have an error:

java.lang.IllegalArgumentException: MainThreadExecutor required
at androidx.paging.PagedList$Builder.build(PagedList.java:355)

But I don't see that setMainThreadExecutor method available, there is only setFetchExecutor:

    val result = list.filter { it.desc?.contains(query, ignoreCase = true) == true }
    val dataSource = MyDataSource(result)
    val mainHandler = Handler(Looper.getMainLooper())
    val pagedList: PagedList<MyDetails> = PagedList.Builder<Int, MyDetails>(dataSource, 500).setFetchExecutor { mainHandler.post(it) }
                .build()

Who knows what's the problem here?

1 Answers

Reading the source, you get this exception if the executor set with setNotifyExecutor() is null. I don't see you call that.

I agree the exception message is somewhat misleading.

For source reference I used this. It's not exactly the same but I believe the androidx version behaves the same here.

Related