其他分享
首页 > 其他分享> > 返回空结果的房间查询可能会使应用崩溃

返回空结果的房间查询可能会使应用崩溃

作者:互联网

我有一个房间查询:

@Query("SELECT * FROM classes WHERE _id IN(:values) ORDER BY date DESC")
fun getClassesByIds(values: List<Int>): Maybe<List<YClass>>
compositeDisposable.add(viewModel.getClassesById(classesTaken)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .doOnSuccess { list ->
                        list.forEach {

                            setupInfo(student)
                        }
                    }
                    .doOnError { it.printStackTrace() }
                    .subscribe())

当结果为空时,当我从活动中导航回来时,应用程序崩溃.
实际上,崩溃是在执行另一个查询时发生的.第二个查询是错误的,即使没有问题.

Caused by: android.arch.persistence.room.EmptyResultSetException:
Query returned empty result set: SELECT * FROM classes WHERE _id IN()
ORDER BY date DESC

03-06 00:07:53.476 31132-31199/? I/InputDispatcher: Window
‘Window{135734f u0
com.labfoodandfriends.nikitagudkovs.jlog/com.labfoodandfriends.nikitagudkovs.jlog.activity.student_and_teacher.StudentOverview}’
spent 4249.1ms processing the last input event: KeyEvent(deviceId=-1,
source=0x00000101, action=1, flags=0x00000048, keyCode=4, scanCode=0,
metaState=0x00000000, repeatCount=0), policyFlags=0x6b000002 03-06
00:07:53.612 13731-13736/com.labfoodandfriends.nikitagudkovs.jlog
I/zygote64: Compiler allocated 6MB to compile void
android.view.ViewRootImpl.performTraversals() 03-06 00:07:53.661
13731-13736/com.labfoodandfriends.nikitagudkovs.jlog I/zygote64: Do
full code cache collection, code=502KB, data=339KB 03-06 00:07:53.662
13731-13736/com.labfoodandfriends.nikitagudkovs.jlog I/zygote64: After
code cache collection, code=501KB, data=295KB 03-06 00:07:55.873
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
io.reactivex.exceptions.OnErrorNotImplementedException: Query returned
empty result set: SELECT * FROM classes WHERE _id IN() ORDER BY date
DESC 03-06 00:07:55.874
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
03-06 00:07:55.875
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
03-06 00:07:55.875
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
io.reactivex.internal.observers.ConsumerSingleObserver.onError(ConsumerSingleObserver.java:47)
03-06 00:07:55.876
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
io.reactivex.internal.operators.single.SingleDoOnError$DoOnError.onError(SingleDoOnError.java:63)
03-06 00:07:55.876
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
io.reactivex.internal.operators.single.SingleDoOnSuccess$DoOnSuccess.onError(SingleDoOnSuccess.java:64)
03-06 00:07:55.877
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
io.reactivex.internal.operators.single.SingleObserveOn$ObserveOnSingleObserver.run(SingleObserveOn.java:79)
03-06 00:07:55.877
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:109)
03-06 00:07:55.878
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at android.os.Handler.handleCallback(Handler.java:790) 03-06
00:07:55.878 13731-13731/com.labfoodandfriends.nikitagudkovs.jlog
W/System.err: at
android.os.Handler.dispatchMessage(Handler.java:99) 03-06 00:07:55.878
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at android.os.Looper.loop(Looper.java:164) 03-06 00:07:55.879
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at android.app.ActivityThread.main(ActivityThread.java:6494) 03-06
00:07:55.879 13731-13731/com.labfoodandfriends.nikitagudkovs.jlog
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
03-06 00:07:55.879
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
03-06 00:07:55.880
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 03-06
00:07:55.881 13731-13731/com.labfoodandfriends.nikitagudkovs.jlog
W/System.err: Caused by:
android.arch.persistence.room.EmptyResultSetException: Query returned
empty result set: SELECT * FROM classes WHERE _id IN() ORDER BY date
DESC 03-06 00:07:55.881
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
com.labfoodandfriends.nikitagudkovs.jlog.database.dao.StudentDAO_Impl$6.call(StudentDAO_Impl.java:345)
03-06 00:07:55.882
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
com.labfoodandfriends.nikitagudkovs.jlog.database.dao.StudentDAO_Impl$6.call(StudentDAO_Impl.java:327)
03-06 00:07:55.882
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
io.reactivex.internal.operators.single.SingleFromCallable.subscribeActual(SingleFromCallable.java:44)
03-06 00:07:55.883
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at io.reactivex.Single.subscribe(Single.java:3096) 03-06 00:07:55.883
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
03-06 00:07:55.884
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:463) 03-06
00:07:55.884 13731-13731/com.labfoodandfriends.nikitagudkovs.jlog
W/System.err: at
io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
03-06 00:07:55.885
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
03-06 00:07:55.885
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at java.util.concurrent.FutureTask.run(FutureTask.java:266) 03-06
00:07:55.885 13731-13731/com.labfoodandfriends.nikitagudkovs.jlog
W/System.err: at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
03-06 00:07:55.886
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
03-06 00:07:55.886
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
03-06 00:07:55.887
13731-13731/com.labfoodandfriends.nikitagudkovs.jlog W/System.err:
at java.lang.Thread.run(Thread.java:764) 03-06 00:07:55.903
13731-13736/com.labfoodandfriends.nikitagudkovs.jlog I/zygote64: Do
partial code cache collection, code=503KB, data=301KB 03-06
00:07:55.904 31132-15809/? W/ActivityManager: Force finishing
activity
com.labfoodandfriends.nikitagudkovs.jlog/.activity.students.StudentsActivity
03-06 00:07:55.909
13731-13736/com.labfoodandfriends.nikitagudkovs.jlog I/zygote64: After
code cache collection, code=503KB, data=301KB 03-06 00:07:55.909
13731-13736/com.labfoodandfriends.nikitagudkovs.jlog I/zygote64:
Increasing code cache capacity to 2MB 03-06 00:07:55.920 31132-31147/?
I/ActivityManager: Showing crash dialog for package
com.labfoodandfriends.nikitagudkovs.jlog u0 03-06 00:07:55.990
31132-1471/? I/OpenGLRenderer: Initialized EGL, version 1.4 03-06
00:07:55.990 31132-1471/? D/OpenGLRenderer: Swap behavior 2 03-06
00:07:56.407 31132-31146/? W/ActivityManager: Activity pause timeout
for ActivityRecord{395d736 u0
com.labfoodandfriends.nikitagudkovs.jlog/.activity.students.StudentsActivity
t7082 f}

解决方法:

对于可能对此问题感兴趣的人:

如这篇文章所述Room with Single explained

如果您在查询中使用Maybe或Single作为返回类型,则查询结果为空时,它将调用Subscriber.onError(newEmptyResultSetException()).因此,这完全可以按预期进行.

标签:rx-java2,android-room,maybe,sql,android
来源: https://codeday.me/bug/20191109/2012513.html