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

时间:2022-10-03 20:29:44

I'm working on an app on Android. I'm using httpcore 4.3.3. I get this when I try to use ContentType.parse(string)

我在Android上开发应用程序。我正在使用httpcore 4.3.3。我尝试使用ContentType.parse(字符串)时得到这个

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)

I've done some googling and I understand why I'm getting the error, but I'm unsure how to fix it. From what I've read, it seems that ContentType tries to make use of the BasicHeaderValueParser that comes with Android and that class doesn't have the INSTANCE field yet. Any help please?

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

These are the relevant imports:

这些是相关的进口:

compile('org.apache.httpcomponents:httpmime:4.3.6') {
    exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpcore:4.3.3'

4 个解决方案

#1


79  

Unfortunately stock versions of HttpCore cannot be used in Android. Please use Apache HttpClient Android Port which also includes requisite HttpCore classes

不幸的是,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'

#2


2  

Download latest Apache Httpclient Jar file and refract path name. That works for me.

下载最新的Apache Httpclient Jar文件并折射路径名称。这对我行得通。

#3


0  

Simple solution is to use:

简单的解决方案是使用:

https://code.google.com/p/httpclientandroidlib/

It's the Appache HttpClient port for android wrap in a different package name so that will not interfere with the existing version in Android. Import the jar in the Android project and instead of "org.apache.http" use "ch.boye.httpclientandroidlib."

这是用于Android包装的Appache HttpClient端口,使用不同的包名,这样就不会干扰Android中的现有版本。在Android项目中导入jar而不是“org.apache.http”使用“ch.boye.httpclientandroidlib”。

#4


0  

Looks like you use incompatible jar's for httpmime and httpclient-android. Try to use version 4.3.6 of httpmime

看起来你使用不兼容的jar为httpmime和httpclient-android。尝试使用httpmime的4.3.6版

#1


79  

Unfortunately stock versions of HttpCore cannot be used in Android. Please use Apache HttpClient Android Port which also includes requisite HttpCore classes

不幸的是,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'

#2


2  

Download latest Apache Httpclient Jar file and refract path name. That works for me.

下载最新的Apache Httpclient Jar文件并折射路径名称。这对我行得通。

#3


0  

Simple solution is to use:

简单的解决方案是使用:

https://code.google.com/p/httpclientandroidlib/

It's the Appache HttpClient port for android wrap in a different package name so that will not interfere with the existing version in Android. Import the jar in the Android project and instead of "org.apache.http" use "ch.boye.httpclientandroidlib."

这是用于Android包装的Appache HttpClient端口,使用不同的包名,这样就不会干扰Android中的现有版本。在Android项目中导入jar而不是“org.apache.http”使用“ch.boye.httpclientandroidlib”。

#4


0  

Looks like you use incompatible jar's for httpmime and httpclient-android. Try to use version 4.3.6 of httpmime

看起来你使用不兼容的jar为httpmime和httpclient-android。尝试使用httpmime的4.3.6版