Org.apache.http.entity.ContentType is no longer in Apache?

For some reason I can not import org.apache.http.entity.ContentType. I added Apache HTTP 4.3.3:

  • client
  • core
  • Common codec
  • HttpClient Cache
  • General logging
  • httpmime
  • free ns

Initially, I did not import all of them, but since the problem persists, I did all of this, and I cleaned up my project and rebuilt it.

import org.apache.http.entity.mime.MultipartEntityBuilder; working

and

import org.apache.http.HttpEntity; also works

but

import org.apache.http.entity.ContentType; not found at all

I am using Android Studio (IntelliJ), so I am not sure if the construction paths are useful here.

I also tried importing via gradle link, but I ran into another error and I need more control over jar files.

+8
java android intellij-idea android-studio apache
source share
3 answers

org.apache.http.entity.ContentType is located in the module org.apache.httpcomponents:httpcore:4.3.x But so org.apache.http.HttpEntity . The fact that you find one and not the other most likely means that they are not extracted from JAR v4.3.x. The Apache HttpCommponents project has recently moved many classes. Thus, it can find HttpEntity in an older / different version of httpcore , which is somehow pulled; A version that does not have a ContentType class. You want to check where HttpEntity is located. There are several ways to see what the addiction depends on.

Option 1 One of the easiest ways is to place the cursor in the class (either in the import statement or in the variable declaration) and open the online documentation ( Ctrl + Q or J ). The dependency in which the class is found is shown at the top of the documentation dialog box:

enter image description here

Option 2 This option will show you if you have multiple instances of the class on the way to your class. Open the Goto Class dialog box ( Ctrl + N or O ) and enter the class name (you can fully qualify or not. You can even enter a name and use the search in the camel case). The class will be found in the list of found classes on the right. enter image description here On the right is the dependency from which the class comes. If it is displayed more than once, it means that it is pulled several times into different banks. This can happen (when using the build tool) if another dependency pulls a different version of httpcore as a transitive dependency. Therefore, you will need to allow this. Note that I have two different variants of the org.springframework.http.HttpEntity class. One is from Spring 3.2.10 and one is from 4.0.6. In this particular case, this is due to the fact that in my project there is a Spring 3.2.x module and a separate Spring 4.0.x module. So I am fine with this, since they do not collide, since these are independent modules. But in most cases this is a concern.

Option 3 You can also open and look at external node libraries in the Project Tool window to see if the dependency will be pulled twice.

It is not clear how your project is set up. You mentioned gradle, but it seemed like a thought after. If you are using maven or gradle and the correct httpcore dependency httpcore declared in your pom or build file, make sure you reimport enter image description here in the corresponding window of the build tool so that it synchronizes correctly and that the module is added to the project dependency. Then use the information above to find out if you have multiple versions of the httpcore module.

+13
source

I had the same problem. You must make sure to use jdk 1.7, not 1.6.

0
source

Download the httpcore-4.3.2 jar and add to the lib folder.

0
source

All Articles