Getting NoSuchFieldError INSTANCE org/apache/http/message/BasicHeaderValueParser
Asked Answered
T

6

29

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'
Thirzia answered 8/12, 2014 at 20:35 Comment(3)
Are you using Proguard?Blanca
i dont think so. i recently upgraded to android studio 1.0 which makes you use minifyEnabled instead of runProguard, i think i have them set to false. i can try setting them to true, but is there another way to fix this? --> didnt seem to fix itThirzia
use jarjar to repackage apache http library or use older httpmime library(chech which verion is compatble with minsdk of your project)Zoogeography
G
91

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'
Giorgione answered 10/12, 2014 at 10:26 Comment(5)
I was trying this approach with httpmim:4.5 and it wasn't working, but with 4.3.6 will (https://mcmap.net/q/501229/-multipartentitybuilder-to-send-pictures-to-rail-server) don't forget that too.Rugging
what all other libraries are required?? because I am getting error - Error:(76, 64) error: cannot access HttpEntity class file for org.apache.http.HttpEntity not found I have used same libraries as mentioned in your reply. Additionally I was redirected from - [link]#32797270England
Ok i found out the solution, check here - #32797270England
@oleg link how do i add it on eclipse?Also when i try to get jar - HttpClient for Android here link the link is dead,what do i doEnclasp
Use 4.3.5.1 instead of 4.3.5 if you want to avoid some errors.Pearsall
P
2

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

Protozoan answered 2/5, 2015 at 4:4 Comment(0)
W
1

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

Wobbly answered 11/4, 2016 at 15:1 Comment(0)
C
1

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)

Carillon answered 10/4, 2019 at 13:37 Comment(0)
C
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."

Cashbook answered 10/4, 2015 at 7:58 Comment(0)
B
-1

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.

Backflow answered 11/9, 2019 at 10:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.