java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET

I am trying to run a java program and I am getting the following run time error.The error is shown below.

Exception in thread "main" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
    at org.apache.http.impl.client.DefaultHttpClient.setDefaultHttpParams(DefaultHttpClient.java:175)
    at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:158)
    at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:448)
    at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:309)
    at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:466)
    at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:286)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:851)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
    at net.floodlightcontroller.core.internal.PacketStreamerClient.registerForPackets(PacketStreamerClient.java:90)
    at net.floodlightcontroller.core.internal.PacketStreamerClient.main(PacketStreamerClient.java:51)

Now the files that I have added to the classpath are the following.

export CLASSPATH=$(JARS=(./lib/*.jar); IFS=:; echo "${JARS[*]}")
export CLASSPATH=$CLASSPATH:~/.m2/repository/org/apache/httpcomponents/httpclient/4.0.1/httpclient-4.0.1.jar
export CLASSPATH=$CLASSPATH:~/.m2/repository/org/apache/httpcomponents/httpcore/4.0.1/httpcore-4.0.1.jar
export CLASSPATH=$CLASSPATH:~/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
export CLASSPAHT=$CLASSPATH:~/ms_thesis/ONOS/httpcore-4.1.jar
#export CLASSPATH=$CLASSPATH:~/ms_thesis/ONOS/lib/httpclient-4.2.jar
export CLASSPATH=$CLASSPATH:~/google-gson-2.2.4/gson-2.2.4.jar

What is the reason for "main" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET

I downloaded http-core-4.1-alpha as that is the jar that contains org/apache/http/params/SyncBasicHttpParams class from findjar.com. So that version of http-core is not negotiable.How do I find out the version of httpclient that is compatible with that version of http-core?


You've got two different versions of httpcore in your classpath:

~/.m2/repository/org/apache/httpcomponents/httpcore/4.0.1/httpcore-4.0.1.jar
~/ms_thesis/ONOS/httpcore-4.1.jar

... although the second one is actually exported as CLASSPAHT according to your question. We also don't know what's in your lib directory - there could be even more versions around.

There would also be two versions of httpclient, except one is commented out. I suggest you sort all of this out so that you're only using the latest versions of both libraries. My guess is that what's actually being picked up is one version of httpclient and one version of httpcore, and they're not compatible. Either that, or just within httpcore there's some manifest entry being picked up from one jar file, but then when a class is asked for it's getting the other.

Either way, having two versions of the same library in your classpath at a time is simply a bad idea.

You should also make sure that the version of httpcore that you use is appropriate for the version of httpclient you use. For example, I've just downloaded the latest version of httpclient (4.2.5) and it uses httpcore 4.2.4. If you're trying to use httpclient-4.2 with httpcore-4.1, that may not be compatible.