线程“main”中的异常 java.lang.NoSuchFieldError: INSTANCE

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37996265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 03:01:00  来源:igfitidea点击:

Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE

javahttpclient

提问by Chuchoo

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

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

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)

回答by Chuchoo

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.

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

回答by Top Sekret

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.sslthan you are using? Upgrade both packages to their newest versions and retry. Report it to HTTPClient bug tracker.

通过分析您的堆栈跟踪,我发现您的程序写得很好。似乎 apache HTTP API 编译错误。也许该软件包org.apache.http.impl.client是针对与org.apache.http.conn.ssl您使用的版本不同的版本编译的?将两个软件包升级到最新版本并重试。将其报告给 HTTPClient 错误跟踪器。

回答by akshaypmurgod

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.

ve 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 SDK是 aws-sdk-s3 或 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).

我在使用 aws-java-sdk-core(1.11.289) 和 aws-sdk-s3(1.11.428) 时遇到了这个错误。通过使用以下 aws-java-sdk-core(1.11.289) 和 aws-sdk-s3(1.11.186) 修复它。