okhttp Fatal Exception thrown on Scheduler.Worker thread问题解决

我在项目里面同时使用了以下两个类库:

compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
compile 'com.squareup.okhttp3:okhttp:3.5.0'

编译时没有错误,但是一调用okhttp方法就报如下错误:

  java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
      at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:62)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
      at java.lang.Thread.run(Thread.java:833)
   Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/internal/Platform;
      at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:112)
      at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:160)
      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
      at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
      at okhttp3.RealCall.execute(RealCall.java:63)
      at retrofit2.OkHttpCall.execute(OkHttpCall.java:177)
      at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:111)
      at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:92)
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50)
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50)
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50)
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
      at rx.Observable.unsafeSubscribe(Observable.java:8452)
      at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)
      at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:222)
      at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423) 
      at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269) 
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
      at java.lang.Thread.run(Thread.java:833) 
   Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.internal.Platform" on path: DexPathList[[zip file "/data/app/org.pyraimds-2/base.apk"],nativeLibraryDirectories=[/data/app/org.pyraimds-2/lib/arm, /data/app/org.pyraimds-2/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]
      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
      at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:112) 
      at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:160) 
      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) 
      at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179) 
      at okhttp3.RealCall.execute(RealCall.java:63) 
      at retrofit2.OkHttpCall.execute(OkHttpCall.java:177) 
      at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:111) 
      at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:92) 
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50) 
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) 
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50) 
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) 
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50) 
      at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) 
      at rx.Observable.unsafeSubscribe(Observable.java:8452) 
      at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94) 
      at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:222) 
      at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) 
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423) 
      at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269) 
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
      at java.lang.Thread.run(Thread.java:833) 
  Suppressed: java.lang.ClassNotFoundException: okhttp3.internal.Platform
      at java.lang.Class.classForName(Native Method)
      at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
      at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
      ... 26 more
   Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available



后来发现是下面这两个类库版本不一致的问题

compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
compile 'com.squareup.okhttp3:okhttp:3.5.0'


修改为同一版本后解决

compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.okhttp3:okhttp:3.4.1'


参考链接:http://stackoverflow.com/questions/39545629/noclassdeffounderror-failed-resolution-of-lokhttp3-internal-platform

根据提供的引用内容,我可以为您介绍一下"Exception in thread 'OkHttp Dispatcher' java.lang.NullPointerException"错误的解决方法。 这个错误通常是由于在使用OkHttp库时,发生了空指针异常导致的。空指针异常意味着您的代码尝试访问一个空对象的属性或方法。 要解决这个问题,您可以按照以下步骤进行操作: 1. 检查代码中的空引用:首先,您需要检查代码中是否存在空引用。确保在使用OkHttp库的地方,没有使用空对象。 2. 检查网络连接:如果您的代码涉及到网络连接,那么请确保您的设备已经连接到网络,并且网络连接是正常的。如果网络连接不稳定或者断开,可能会导致OkHttp库出现空指针异常。 3. 检查OkHttp版本:如果您使用的是较旧的OkHttp版本,那么可能会存在一些已知的问题和bug。请尝试升级到最新版本的OkHttp库,以解决可能存在的问题。 4. 检查代码逻辑:仔细检查您的代码逻辑,确保在使用OkHttp库的地方,没有遗漏任何必要的参数或者方法调用。确保您正确地使用了OkHttp库提供的方法和功能。 5. 使用调试工具:如果以上步骤都没有解决问题,您可以尝试使用调试工具来定位问题。通过在代码中设置断点,并使用调试工具逐步执行代码,您可以找到导致空指针异常的具体位置,并进行修复。 希望以上解决方法能够帮助您解决"Exception in thread 'OkHttp Dispatcher' java.lang.NullPointerException"错误。如果您还有其他问题,请随时提问。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值