大佬教程收集整理的这篇文章主要介绍了致命异常:java.io.InvalidObjectException:前置错误,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在做 Nasa APP,使用带缓存的分页库,当我删除模拟器中的所有数据时启动模拟器时出现此错误
E/AndroIDRuntime: FATAL EXCEPTION: main
Process: com.baish.skyscanner,PID: 8989
java.io.InvalidobjectException: prepend error
at com.baish.skyscanner.data.PagingMediator.load(PagingMediator.kt:34)
at androIDx.paging.RemoteMediatorAccessImpl$launchBoundary$1$1.invokeSuspend(RemoteMediatorAccessor.kt:342)
at androIDx.paging.RemoteMediatorAccessImpl$launchBoundary$1$1.invoke(UnkNown Source:10)
at androIDx.paging.SingleRunner$runInIsolation$2.invokeSuspend(SingleRunner.kt:59)
at androIDx.paging.SingleRunner$runInIsolation$2.invoke(UnkNown Source:10)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:91)
at kotlinx.coroutines.CoroutinescopeKt.coroutinescope(Coroutinescope.kt:194)
at androIDx.paging.SingleRunner.runInIsolation(SingleRunner.kt:49)
at androIDx.paging.RemoteMediatorAccessImpl$launchBoundary$1.invokeSuspend(RemoteMediatorAccessor.kt:335)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.dispatchedContinuationKt.resumeCancellableWith(dispatchedContinuation.kt:342)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:27)
at kotlinx.coroutines.Coroutinestart.invoke(Coroutinestart.kt:109)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:158)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
at kotlinx.coroutines.BuildersKt.launch(UnkNown Source:1)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:49)
at kotlinx.coroutines.BuildersKt.launch$default(UnkNown Source:1)
at androIDx.paging.RemoteMediatorAccessImpl.launchBoundary(RemoteMediatorAccessor.kt:334)
at androIDx.paging.RemoteMediatorAccessImpl.access$launchBoundary(RemoteMediatorAccessor.kt:234)
at androIDx.paging.RemoteMediatorAccessImpl$launchrefresh$1.invokeSuspend(RemoteMediatorAccessor.kt:328)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:32)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:113)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
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:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.androID.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:807)
但是当你运行模拟器时,一切对我来说都很好,我找不到错误 这是我的分页课,这里我使用了房间分页
const val START_PAGE = 1
@ExperimentalPagingAPI
class PagingMediator(
private val service: NasaService,private val db: AppDataBase,) : RemoteMediator<Int,Photos>() {
overrIDe suspend fun load(loadType: LoadType,state: PagingState<Int,Photos>): MediatorResult {
val page = when (loadType) {
LoadType.REFRESH -> {
val remoteKeys = getRemoteKeysToCurrentposition(state)
remoteKeys?.nextKey?.minus(1) ?: START_PAGE
}
LoadType.PREPEND -> {
val remoteKeys = getRemoteKeyforFirstItem(state)
?: throw InvalidobjectException("prepend error")
remoteKeys.prevKey ?: return MediatorResult.Success(
endOfPaginationReached = true
)
remoteKeys.prevKey
}
LoadType.APPEND -> {
val remoteKeys =
getRemoteKeysForLastItem(state) ?: throw InvalidobjectException("append error")
if (remoteKeys.nextKey == null) throw InvalidobjectException("append error")
remoteKeys.nextKey
}
}
try {
Log.d("gdfgd",page.toString())
val APIResponse = service.getMars(sol = state.config.pageSize,page = page,API_key = "EnKUTj7VDqVE0Cnu63SCYny69JzzTllJdhzVCmZb")
val endofPaginationReached = APIResponse.photos.isEmpty()
db.withTransaction {
if (loadType == LoadType.REFRESH) {
db.getContentDao().deletealL()
db.getPagigngKeysDao().deleteall()
}
val prevKey = if (page == START_PAGE) null else page - 1
val nextKey = if (endofPaginationReached) null else page + 1
val keys = APIResponse.photos.map {
PageKeys(ID = it.ID,prevKey = prevKey,nextKey = nextKey)
}
db.getPagigngKeysDao().insertAll(keys)
db.getContentDao().insert(APIResponse.photos)
}
return MediatorResult.Success(endOfPaginationReached = endofPaginationReached)
} catch (e : IOException){
return MediatorResult.Error(e)
} catch (e: httpException){
return MediatorResult.Error(e)
}
}
private suspend fun getRemoteKeysToCurrentposition(
state: PagingState<Int,Photos>,): PageKeys? {
return state.anchorposition?.let { position ->
state.closestItemToposition(position)?.ID.let { repoID ->
db.getPagigngKeysDao().getKeyID(repoID)
}
}
}
private suspend fun getRemoteKeyforFirstItem(state: PagingState<Int,Photos>): PageKeys? {
return state.pages.firstOrNull { it.data.isNotEmpty() }?.data?.firstOrNull()
?.let { repo ->
db.getPagigngKeysDao().getKeyID(repo.ID)
}
}
private suspend fun getRemoteKeysForLastItem(state: PagingState<Int,Photos>): PageKeys? {
return state.pages.lastOrNull { it.data.isNotEmpty() }?.data?.lastOrNull()
?.let { repo ->
db.getPagigngKeysDao().getKeyID(repo.ID)
}
}
}
错误正好发生在这部分
LoadType.PREPEND -> {
val remoteKeys = getRemoteKeyforFirstItem(state)
?: throw InvalidobjectException("prepend error")
remoteKeys.prevKey ?: return MediatorResult.Success(
endOfPaginationReached = true
)
remoteKeys.prevKey
}
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的致命异常:java.io.InvalidObjectException:前置错误全部内容,希望文章能够帮你解决致命异常:java.io.InvalidObjectException:前置错误所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。