I copied a code that worked fine in an Eclipse Java project to an Android project, and even though I import the same .jars, I get compilation errors in the Android project.
In the Android project, Eclipse shows the error “The constructor StringEntity(String, String, String) is undefined” in the following line:
StringEntity se = new StringEntity("example data.", "application/json", "UTF-8");
But in the other Java project, it compiles and runs fine. The documentation says that the constructor StringEntity(String string, String mimeType, String charset) does exist.
I’m importing the same org.apache.http.entity.StringEntity in the two projects. The jars used in the Eclipse project are the same used in the Android project. I even copied and pasted them. I cleaned the project too. Still no success. Can anyone please explain to me why this error is happening?
Android doesn’t use the latest version of HttpClient 4.x.
The Android version of
StringEntitycurrently only has these constructors:StringEntity(String s, String charset)StringEntity(String s)I assume that the Android SDK classes are taking precedence over the same classes you provide as JARs. I’d remove the JARs to avoid this kind of confusion in the future — having different versions of the same classes never did anyone good.