gpt4 book ai didi

java - 线程 "main"java.lang.NoSuchFieldError : INSTANCE 中的异常

转载 作者:行者123 更新时间:2023-12-01 04:59:35 25 4
gpt4 key购买 nike

我正在尝试使用 HTTPClient 编写一个简单的 WebService 测试。我已经加载了所有的 jar ,但收到了上述错误消息。

为什么我会收到此错误消息?

这是代码:

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);
}

}

下面是错误堆栈跟踪,
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)

最佳答案

我收到上述错误是因为我的项目中有多个旧版本的 HTTPClient。我删除了旧版本的 HTTPClient,现在错误消息消失了。

关于java - 线程 "main"java.lang.NoSuchFieldError : INSTANCE 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37996265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com