Java Error - Exception in thread "main" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET


Many of you will get this exception when using HttpClient in your java application

Exception in thread "main" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
 at org.apache.http.impl.client.DefaultHttpClient.setDefaultHttpParams(
 at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(
 at org.apache.http.impl.client.AbstractHttpClient.getParams(
 at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(
 at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(
 at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(
 at org.apache.http.impl.client.AbstractHttpClient.execute(
 at org.apache.http.impl.client.DecompressingHttpClient.execute(
 at org.apache.http.impl.client.DecompressingHttpClient.execute(


  • You got multiple versions of HttpClient
  • Incompatible httpclient.jar and httpcore.jar
For example: Using httpclient-4.2.3.jar and http-core-4.1.jar together will throw this exception. These two jar files are not compatible.
Using httpcore-4.4.jar and httpclient-4.4.jar together will work just fine.

If you have both httpclient-4.4.jar and httpclient-4.2.3.jar, you are most likely to get exceptions. Please remove the older one from your project build path.

  • Remove duplicate versions of HttpClient
  • Use compatible versions of httpclient.jar and httpcore.jar (Use the latest versions if possible).

No comments:
Write comments

Popular Posts

Find us on Facebook