Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
16,989
Solution 1
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.
Solution 2
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.client
was 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.
Author by
Chuchoo
Updated on June 05, 2022Comments
-
Chuchoo almost 2 years
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)