代码之家  ›  专栏  ›  技术社区  ›  Rainmaker

Android分页库java.lang.illegalargumentException:需要MainthreaDexecutor

  •  1
  • Rainmaker  · 技术社区  · 6 年前

    我正在使用Android分页库 androidx.paging:paging-runtime:2.0.0 建立一个列表。问题是当我想建立 PagedList ( LivePagedList 我有一个错误:

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

    但我看不出来 setMainThreadExecutor 方法可用,只有 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()
    

    谁知道这里有什么问题?

    1 回复  |  直到 6 年前
        1
  •  1
  •   laalto    6 年前

    如果执行器设置了 setNotifyExecutor() 是空的。我看不出你这么叫。

    我同意例外信息有些误导。

    作为参考资料 this . 这并不完全相同,但我相信Androidx版本在这里的表现是一样的。