Getting NoSuchFieldError INSTANCE org/apache/http/message/BasicHeaderValueParser

我是研究僧i 提交于 2019-11-26 07:33:40

问题


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)

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?

These are the relevant imports:

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

回答1:


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

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



回答2:


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




回答3:


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




回答4:


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."




回答5:


Just add httpmime_4.3.6.jar of version 4.3.6 file in lib folder and add

implementation files('lib/httpmime-4.3.6.jar') in gradle(app level)




回答6:


Note : If you are using both apache httpmime and retrofit simultaneously Use apache httpmime older version.

(eg : in my case i used this to upload a image on server and also to get the content lenghth/image size)

This his an older version (not so old) or prev version, You should implement same old version for both.

implementation 'com.squareup.retrofit2:retrofit:2.0.2' implementation 'org.apache.httpcomponents:httpmime:4.3.6'

This his an new version of retrofit, You should use old version apache httpmime.

implementation 'com.squareup.retrofit2:retrofit:2.3.0' implementation 'org.apache.httpcomponents:httpmime:4.3.6'

Thank You so much, If u loved my solution plz voteup for me.



来源:https://stackoverflow.com/questions/27366430/getting-nosuchfielderror-instance-org-apache-http-message-basicheadervalueparser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!