使用OkHttp时的java.lang.VerifyError

时间:2015-05-25 09:01:11

标签: android okhttp okio

我在android studio项目中使用此代码:

HttpUrl url = new HttpUrl.Builder().scheme("http").host("www.somesite.com")
                                    .addPathSegment("kontakt")
                                    .addQueryParameter("yit_contact[imie]", name)
                                    .addQueryParameter("yit_contact[email]", email)
                                    .addQueryParameter("yit_contact[telefon]", telephone)
                                    .addQueryParameter("yit_contact[wiadomosc]", message)
                                    .addQueryParameter("yit_bot", "")
                                    .addQueryParameter("_wp_http_referer", "/kontakt/").build();
Request request = new Request.Builder().url(url).build();
Response response = new OkHttpClient().newCall(request).execute();

我尝试获取Response对象时出现此错误:

java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:299)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
        at java.util.concurrent.FutureTask.run(FutureTask.java:239)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:856)
 Caused by: java.lang.VerifyError: com/squareup/okhttp/internal/http/HttpConnection$AbstractSource
        at com.squareup.okhttp.internal.http.HttpConnection.newFixedLengthSource(HttpConnection.java:246)
        at com.squareup.okhttp.internal.http.HttpTransport.getTransferStream(HttpTransport.java:125)
        at com.squareup.okhttp.internal.http.HttpTransport.openResponseBody(HttpTransport.java:110)
        at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:926)
        at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:95)
        at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:902)
        at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:760)
        at com.squareup.okhttp.Call.getResponse(Call.java:274)
        at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230)
        at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201)
        at com.squareup.okhttp.Call.execute(Call.java:81)
        at com.example.tomek.myapplication.KontaktActivity$SendEmail.doInBackground(KontaktActivity.java:135)
        at com.example.tomek.myapplication.KontaktActivity$SendEmail.doInBackground(KontaktActivity.java:87)
        at android.os.AsyncTask$2.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
            at java.lang.Thread.run(Thread.java:856)

我已将jar文件添加到项目中:

compile files('libs/okhttp-2.4.0.jar')
compile files('libs/okio-1.0.0.jar')

帮助。

1 个答案:

答案 0 :(得分:1)

尝试添加OkHttp 2.4.0所需的Okio-1.4.0。

<dependency>
  <groupId>com.squareup.okio</groupId>
  <artifactId>okio</artifactId>
  <version>1.4.0</version>
</dependency>