简体   繁体   English

Java Http客户端-无此类字段错误

[英]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: 我正在尝试使用Digital Ocean Java库,并在尝试使用以下方法创建连接时:

CloseableHttpClient httpClient = HttpClients.createDefault();

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

The problem lies in the CloseableHttpClient httpClient object. 问题出在CloseableHttpClient httpClient对象上。 The library uses httpcore version 4.4.1 and httpclient version 4.5. 该库使用httpcore版本4.4.1和httpclient版本4.5。 It gives me a java.lang.NoSuchFieldError. 它给了我一个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. 我在NoSuchFieldError上发现的信息和文档很少,所以我假设它与导致此错误的httpcore和/或httpclient版本有关。

The field variable INSTANCE has been introduced in AllowAllHostnameVerifier.java since Apache httpclient version 4.4. 自Apache httpclient版本4.4起,在AllowAllHostnameVerifier.java中引入了字段变量INSTANCE

If both new version of SSLConnectionSocketFactory and old version of AllowAllHostnameVerifier is used, then java.lang.NoSuchFieldError: INSTANCE is thrown. 如果同时使用新版本的SSLConnectionSocketFactory和旧版本的AllowAllHostnameVerifier ,则将引发java.lang.NoSuchFieldError: INSTANCE

One of the possible cause is two version of Apache httpclient jar are in your library directory. 可能的原因之一是您的库目录中有两个版本的Apache httpclient jar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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