4

I am trying to write a simple WebService Testing using HTTPClient. I have all my jars loaded up but get the above error message.

Why am I getting this error message?

Here is the code:

package HTTPClientTest; import java.io.IOException; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.HttpClientBuilder; import org.junit.Assert; public class RESTTester { public static void main (String args[]) { String restURL_XML = "http://parabank.parasoft.com/parabank/services/bank/customers/12212/"; try { testStatusCode(restURL_XML); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void testStatusCode(String restURL) throws ClientProtocolException, IOException { HttpUriRequest request = new HttpGet(restURL); HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request); Assert.assertEquals(httpResponse.getStatusLine().getStatusCode(),HttpStatus.SC_OK); } } 

Below is the error stacktrace,

Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144) at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:966) at HTTPClientTest.RESTTester.testStatusCode(RESTTester.java:37) at HTTPClientTest.RESTTester.main(RESTTester.java:22) 
2
  • Could you share your stack trace with me? I can't do anything without that. Commented Jun 23, 2016 at 15:47
  • @Chuchoo please edit the stacktrace into the question.. Commented Jun 23, 2016 at 15:53

4 Answers 4

12

I got above error because I had multiple older versions of HTTPClient in my project. I removed older versions of HTTPClient and now the error message is gone.

Sign up to request clarification or add additional context in comments.

3 Comments

I had the same reason.
which version should I use?
i had same issue. removing older version jars from classpath fixed the issue
1

By analysing your stack trace, I found out your program is written good. It seems that apache HTTP APIs were compiled wrong. Maybe the package org.apache.http.impl.clientwas compiled against different version of org.apache.http.conn.ssl than you are using? Upgrade both packages to their newest versions and retry. Report it to HTTPClient bug tracker.

Comments

0

I had same problem. I found a jar named apache-httpcomponents-httpcore.jar beside httpclient-4.4.1.jar and httpcore-4.4.1.jar.

I just remove the apache-httpcomponents-httpcore.jar and worked fine.

Comments

-1

Ive come across this error(java.lang.NoSuchFieldError: INSTANCE) several times. With different reasons here it is INSTANCE. This error is conveying about the mismatch between the aws-java-sdk-core library and one of the service-specific SDKs aws-sdk-s3 or aws-java-sdk-sqs.

I faced this error while using aws-java-sdk-core(1.11.289) with aws-sdk-s3(1.11.428). Fixed it by using the following aws-java-sdk-core(1.11.289) with aws-sdk-s3(1.11.186).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.