异常记录:java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34261214/article/details/81456271

异常描述

  • 有两处报错
 Caused by: java.lang.NoSuchMethodError:No virtual method isSuccess()Z in class Lretrofit2/Response;

 java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread
  • 使用环境
    1. 使用Retorfit结合Rxjava实现网络请求
    2. 在retrofit中添加拦截器

原因分析

基于okhttp3的拦截器版本与retrofit使用的版本不一致

解决方法

这是我改正后的依赖配置
retrofit最新版本是2.4.0,基于okhttp3的3.11.0版本,所以把 拦截器的版本修正为3.11.0

    //retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'io.reactivex:rxandroid:1.1.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.4.0'
    implementation 'com.trello.rxlifecycle2:rxlifecycle:2.2.1'
    implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'

* 注意:在使用retrofit过程中无需另外添加okhtt3的依赖,本身已实现okhttp3的支持*

猜你喜欢

转载自blog.csdn.net/qq_34261214/article/details/81456271
今日推荐