大家好,又见面了,我是你们的朋友全栈君。
这个问题发现是由于版本问题引起的,下面是我用的两个jar源码对比: 先看看okio-1.13.0.jar的,会发现在forwardingSource下面有ForwardingTimeout这个类
下面是okio-2.0.0.jar 包,会发现那个ForwardingTimeout没了,不知道官方改成什么了
我用okhttp-3.8.0.jar引用okio-2.0.0.jar的时候就会报
代码语言:javascript复制Exception in thread "main" java.lang.NoClassDefFoundError: okio/ForwardingTimeout
at okhttp3.internal.http1.Http1Codec.newFixedLengthSink(Http1Codec.java:230)
at okhttp3.internal.http1.Http1Codec.createRequestBody(Http1Codec.java:103)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:60)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
at okhttp3.RealCall.execute(RealCall.java:69)
at com.test.httpclient.HttpClientUtil.postJson(HttpClientUtil.java:141)
at com.test.httpclient.HttpClientUtil.main(HttpClientUtil.java:301)
Caused by: java.lang.ClassNotFoundException: okio.ForwardingTimeout
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 19 more
然后换到okio-1.13.0.jar,这个错误就没了
注意:okio-1.13.0.jar是com.squareup.okio的
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/139709.html原文链接:https://javaforall.cn