简体   繁体   中英

Java Http Client - No Such Field Error

I am trying to use the Digital Ocean java library and when trying to create a connection with:

CloseableHttpClient httpClient = HttpClients.createDefault();

client = new DigitalOceanClient("v2", token, httpClient);

The problem lies in the CloseableHttpClient httpClient object. The library uses httpcore version 4.4.1 and httpclient version 4.5. It gives me a java.lang.NoSuchFieldError.

Here's my log:

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:955)
at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:58)
at main.java.servers.DigitalOceanServer.setup(DigitalOceanServer.java:28)

I found little information and documentation on the NoSuchFieldError, so I'm assuming it has to do with the version of httpcore and/or httpclient that causes this error.

The field variable INSTANCE has been introduced in AllowAllHostnameVerifier.java since Apache httpclient version 4.4.

If both new version of SSLConnectionSocketFactory and old version of AllowAllHostnameVerifier is used, then java.lang.NoSuchFieldError: INSTANCE is thrown.

One of the possible cause is two version of Apache httpclient jar are in your library directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM