简体   繁体   English

引起原因:java.lang.RuntimeException:java.lang.InterruptedException

[英]Caused by: java.lang.RuntimeException: java.lang.InterruptedException

Use implementation 'io.reactivex.rxjava2:rxjava:2.1.9' 使用实现'io.reactivex.rxjava2:rxjava:2.1.9'

I am trying parsing withe rxJava. 我正在尝试使用rxJava进行解析。 Parse long json data. 解析长json数据。 So my parse take time. 所以我的解析需要时间。 But if user leave screen my parsing need finish work but instead my app crashes. 但是,如果用户离开屏幕,我的解析需要完成工作,但我的应用程序崩溃。 Method for parsing: 解析方法:

    override fun restore(): Observable<List<Pair<String, String>?>> {
return backupRemoteSource.getBackup()
                .flatMap { urlBackup ->
                    Observable.create<Boolean> { emitter ->
                        var isRestore = true
                        try {
                            val url = URL(urlBackup)
                            url.openConnection()
                            InputStreamReader(url.openStream(), "UTF-8").use {
                                val jsonReader = JsonReader(it)

                                jsonReader.beginArray()

                                var tour: Tour? = null

                                /* tours */
                                while (jsonReader.hasNext() ) {

                                    /* tour item*/
                                    jsonReader.beginObject()
                                    while (jsonReader.hasNext() && isRestore) {

                                        val name = jsonReader.nextName()

                                        when (name) {

                                            "tourInfo" -> {

                                                tour = tourMapper.fromRx(gsonParser.fromJson<TourBackup>(jsonReader, TourBackup::class.java))
                                                        .flatMap {


                                                            tourLocalSource.save(it)
                                                        }.blockingFirst()

                                                Log.i(tag, "\n@saved tour")
                                            }

                                      jsonReader.endArray()
                                            }
                                        }

                                    }
                                    jsonReader.endObject()
                                }
                                jsonReader.endArray()

                                emitter.onNext(true)
                            }
                        } catch (error: InterruptedException) {
                            emitter.onError(BackupException(error.message ?: "unknown exception"))
                        } catch (error: NoSuchFileException) {
                            emitter.onError(BackupException(error.message ?: "unknown exception"))
                        } catch (error: IOException) {
                            emitter.onError(BackupException(error.message ?: "unknown exception"))
                        }

                        emitter.setCancellable({
                            Log.d(tag,"cancel restore")
                            isRestore = false
                        })
                    }

                }
....}

then i call: 然后我打电话给:

fun restore() {

    disposables.add(backUpRepo.restore()
            .compose(RxUtils.ioToMainTransformer())
            .subscribe()
}

but when calling during long data parsing: 但是在长时间数据解析期间调用时:

disposables.dispose()

i get crash: 我崩溃了:

  04-23 14:57:27.456 28001-28063/com.jellyworkz.udark.debug E/AndroidRuntime: FATAL EXCEPTION: RxCachedThreadScheduler-1
    Process: com.jellyworkz.udark.debug, PID: 28001
    io.reactivex.exceptions.UndeliverableException: java.lang.RuntimeException: java.lang.InterruptedException


....

    Caused by: java.lang.RuntimeException: java.lang.InterruptedException
        at io.reactivex.internal.util.ExceptionHelper.wrapOrThrow(ExceptionHelper.java:45)
        at io.reactivex.internal.observers.BlockingBaseObserver.blockingGet(BlockingBaseObserver.java:74)
        at io.reactivex.Observable.blockingFirst(Observable.java:4987)
        at com.jellyworkz.udark.backup.source.BackupRepositoryImpl$restore$1$1.subscribe(BackupRepositoryImpl.kt:113)

Where do i wrong? 我哪里错了?

Just used emitter.tryOnError 刚刚使用了emitter.tryOnError

   try{

    ....

    } catch (error: InterruptedException) {
         emitter.tryOnError(BackupException(error.message ?: "unknown exception"))
    }

see more details 查看更多详情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 原因:java.lang.ExceptionInInitializerError原因:java.lang.RuntimeException - Caused by: java.lang.ExceptionInInitializerError Caused by: java.lang.RuntimeException Android 引起的:java.lang.RuntimeException - Android Caused by: java.lang.RuntimeException 使用swingworker的java.lang.InterruptedException - java.lang.InterruptedException using swingworker 未处理的异常:java.lang.InterruptedException - Unhandled Exception: java.lang.InterruptedException Azure MobileService EasyApi java.lang.interruptedException - Azure MobileService EasyApi java.lang.interruptedException java.lang.RuntimeException:原因:java.lang.IllegalStateException: - java.lang.RuntimeException: Caused by: java.lang.IllegalStateException: java.lang.RuntimeException - 原因:java.lang.ArithmeticException - java.lang.RuntimeException - Caused by: java.lang.ArithmeticException 由java.lang.NullPointerException和java.lang.RuntimeException引起 - Caused by java.lang.NullPointerException and java.lang.RuntimeException 使用Process.waitFor()和java.lang.InterruptedException的Java多线程 - java multithreading using Process.waitFor() and java.lang.InterruptedException 由应用程序启动方法中的java.lang.runtimeexception异常引起 - caused by java.lang.runtimeexception exception in application start method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM