异常描述
- 有两处报错
Caused by: java.lang.NoSuchMethodError:No virtual method isSuccess()Z in class Lretrofit2/Response;
java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread
- 使用环境
- 使用Retorfit结合Rxjava实现网络请求
- 在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的支持*