获取NoSuchFieldError INSTANCE org/apache/http/message/BasicHeaderValueParser

jos*_*ick 27 android apache-httpclient-4.x androidhttpclient

我正在研究Android上的应用.我正在使用httpcore 4.3.3.我尝试使用时会得到这个ContentType.parse(string)

java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/message/BasicHeaderValueParser; in class Lorg/apache/http/message/BasicHeaderValueParser; or its superclasses (declaration of 'org.apache.http.message.BasicHeaderValueParser' appears in /system/framework/ext.jar)
Run Code Online (Sandbox Code Playgroud)

我做了一些谷歌搜索,我理解为什么我得到错误,但我不确定如何解决它.从我读过的内容来看,似乎ContentType试图利用Android附带的BasicHeaderValueParser,而该类还没有INSTANCE字段.有什么帮助吗?

这些是相关的进口:

compile('org.apache.httpcomponents:httpmime:4.3.6') {
    exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpcore:4.3.3'
Run Code Online (Sandbox Code Playgroud)

ok2*_*k2c 90

不幸的是,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'
Run Code Online (Sandbox Code Playgroud)

  • 如果我能,我会给你超过1 upvote (12认同)
  • 我正在尝试这种方法使用httpmim:4.5并且它无法正常工作,但是使用4.3.6(http://stackoverflow.com/a/29473284/1423773)并不会忘记这一点. (4认同)