3

我使用分页 3.0.0-alpha10 创建了我的 pagingSource 类,它可以工作,但是当我将版本更改为 3.0.0-alpha12 时,我收到此错误,这是运行时异常:

java.lang.AbstractMethodError: abstract method "java.lang.Object androidx.paging.PagingDataDiffer.presentNewList(androidx.paging.NullPaddedList, androidx.paging.NullPaddedList, androidx.paging.CombinedLoadStates, int, kotlin.jvm.functions.Function0, kotlin.coroutines.Continuation)"
        at androidx.paging.PagingDataDiffer$collectFrom$2$invokeSuspend$$inlined$collect$1$lambda$1.invokeSuspend(PagingDataDiffer.kt:136)
        at androidx.paging.PagingDataDiffer$collectFrom$2$invokeSuspend$$inlined$collect$1$lambda$1.invoke(Unknown Source:10)
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:91)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:161)
        at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
        at androidx.paging.PagingDataDiffer$collectFrom$2$invokeSuspend$$inlined$collect$1.emit(Collect.kt:133)
        at kotlinx.coroutines.flow.FlowKt__ChannelsKt.emitAllImpl$FlowKt__ChannelsKt(Channels.kt:61)
        at kotlinx.coroutines.flow.FlowKt__ChannelsKt$emitAllImpl$1.invokeSuspend(Unknown Source:11)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:69)
        at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:236)
        at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161)
        at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:362)
        at kotlinx.coroutines.CancellableContinuationImpl.completeResume(CancellableContinuationImpl.kt:479)
        at kotlinx.coroutines.channels.AbstractChannel$ReceiveElement.completeResumeReceive(AbstractChannel.kt:899)
        at kotlinx.coroutines.channels.ArrayChannel.offerInternal(ArrayChannel.kt:84)
        at kotlinx.coroutines.channels.AbstractSendChannel.send(AbstractChannel.kt:135)
        at androidx.paging.PageFetcherSnapshot.doInitialLoad(PageFetcherSnapshot.kt:315)
        at androidx.paging.PageFetcherSnapshot$doInitialLoad$1.invokeSuspend(Unknown Source:11)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6543)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)

这是我的 PaginSource:

import androidx.paging.PagingSource
import com.example.template.api.MyApi
import com.example.template.api.responses.ChatHistoryResponse
import retrofit2.HttpException
import java.io.IOException

class ChatHistoryPagingSource
constructor(
    private val myApi: MyApi,
    private val search: String,
    private val type: String,
    private val token: String,
    private val status: String,
    ): PagingSource<Int, ChatHistoryResponse>() {

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, ChatHistoryResponse> {
        val position = params.key ?: 1
        return try {
            val response = myApi.chatHistoryList(token, status, position, 20, type, search)
            LoadResult.Page(
                data = response,
                prevKey = if (position == 1) null else position -1,
                nextKey = if (response.isEmpty()) null else position +1
            )

        } catch (exception: IOException) {
            LoadResult.Error(exception)
        } catch (exception: HttpException) {
            LoadResult.Error(exception)
        }
    }

}

它在以前的版本中完全可以工作,但我必须迁移到新版本。

4

1 回答 1

3

很可能,您使用的 gradle 依赖项彼此不兼容。

就我而言,当我使用androidx.room:room-paging:2.4.0-alpha05with时发生异常androidx.paging:paging-compose:1.0.0-alpha12。我通过将分页组合的版本调整为1.0.0-alpha13.

于 2021-10-05T15:39:22.367 回答