无法解析Apache HTTP库以发送请求和接收响应

时间:2015-11-25 07:36:13

标签: android apache httprequest httpresponse apache-mina

我正在尝试使用Apache HTTP Library上传图像,但我会遇到这种错误。

    Caused by: java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/message/BasicHeaderValueFormatter; in class Lorg/apache/http/message/BasicHeaderValueFormatter; or its superclasses (declaration of 'org.apache.http.message.BasicHeaderValueFormatter' appears in /system/framework/ext.jar)

at org.apache.http.entity.ContentType.toString(ContentType.java:153) 它会给库错误并导致我的应用程序崩溃。无法找到有关此问题的解决方案

here is my logcat.

          E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #5
          Process: com.technotechindia.talknshop, PID: 9660
         java.lang.RuntimeException: An error occured while executing doInBackground()
         at android.os.AsyncTask$3.done(AsyncTask.java:304)
         at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
         at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
         at java.util.concurrent.FutureTask.run(FutureTask.java:242)
         at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
         at java.lang.Thread.run(Thread.java:818)
         Caused by: java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/message/BasicHeaderValueFormatter; in class Lorg/apache/http/message/BasicHeaderValueFormatter; or its superclasses (declaration of 'org.apache.http.message.BasicHeaderValueFormatter' appears in /system/framework/ext.jar)
  at org.apache.http.entity.ContentType.toString(ContentType.java:153)
  at org.apache.http.entity.mime.MultipartFormEntity.<init>(MultipartFormEntity.java:53)
  at org.apache.http.entity.mime.MultipartEntityBuilder.buildEntity(MultipartEntityBuilder.java:236)
          at         org.apache.http.entity.mime.MultipartEntity.getEntity(MultipartEntity.java:119)
          at org.apache.http.entity.mime.MultipartEntity.isChunked(MultipartEntity.java:138)
         at org.apache.http.protocol.RequestContent.process(RequestContent.java:84)
  at org.apache.http.protocol.BasicHttpProcessor.process(BasicHttpProcessor.java:295)
  at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:165)
  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:427)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:580)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:503)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:481)
  at com.technotechindia.talknshop.AddStoreToLocation$UploadImages.doInBackground(AddStoreToLocation.java:454)
  at com.technotechindia.talknshop.AddStoreToLocation$UploadImages.doInBackground(AddStoreToLocation.java:372)
  at android.os.AsyncTask$2.call(AsyncTask.java:292)
  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
  at java.lang.Thread.run(Thread.java:818) 

所以每当我要请求服务器给我这种错误

2 个答案:

答案 0 :(得分:2)

不幸的是,HttpCore的库存版本无法在Android中使用。请使用Apache HttpClient Android端口,其中还包括必需的HttpCore类

compile('org.apache.httpcomponents:httpmime:4.3.6') {
    exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'

答案 1 :(得分:0)

为我工作

compile 'org.apache.httpcomponents:httpmime:4.3.6'
compile 'org.apache.httpcomponents:httpcore:4.4.5'