简体   繁体   English

线程“主”java.lang.NoSuchFieldError 中的异常:实例

[英]Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE

I am trying to write a simple WebService Testing using HTTPClient.我正在尝试使用 HTTPClient 编写一个简单的 WebService 测试。 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)

I got above error because I had multiple older versions of HTTPClient in my project.我收到上述错误是因为我的项目中有多个旧版本的 HTTPClient。 I removed older versions of HTTPClient and now the error message is gone.我删除了旧版本的 HTTPClient,现在错误消息消失了。

By analysing your stack trace, I found out your program is written good.通过分析你的堆栈跟踪,我发现你的程序写得很好。 It seems that apache HTTP APIs were compiled wrong.似乎 apache HTTP API 编译错误。 Maybe the package org.apache.http.impl.client was compiled against different version of org.apache.http.conn.ssl than you are using?也许包org.apache.http.impl.client是针对与您使用的不同版本的org.apache.http.conn.ssl编译的? Upgrade both packages to their newest versions and retry.将这两个软件包升级到最新版本并重试。 Report it to HTTPClient bug tracker.将其报告给 HTTPClient 错误跟踪器。

I 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 SDKve 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 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 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 s 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 s 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).我在将 aws-java-sdk-core(1.11.289) 与 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.186) 一起使用来修复它。

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

相关问题 线程“主”中的异常java.lang.NoSuchFieldError:AWS SNS中的INSTANCE - Exception in thread “main” java.lang.NoSuchFieldError: INSTANCE in AWS SNS HTTPClient 示例 - 线程“main”中的异常 java.lang.NoSuchFieldError: INSTANCE - HTTPClient Example - Exception in thread “main” java.lang.NoSuchFieldError: INSTANCE 如何解决线程“main”中的异常 java.lang.NoSuchFieldError: INSTANCE? - How to solve Exception in thread “main” java.lang.NoSuchFieldError: INSTANCE? “线程“主”中的异常 java.lang.NoSuchFieldError:” - "Exception in thread "main" java.lang.NoSuchFieldError:" 线程“ main”中的异常java.lang.NoSuchFieldError:JAVA_VENDOR - Exception in thread “main” java.lang.NoSuchFieldError: JAVA_VENDOR 线程“ main”中的异常java.lang.NoSuchFieldError:文件系统 - Exception in thread “main” java.lang.NoSuchFieldError: filesystem 线程“main”中的异常 java.lang.NoSuchFieldError: LINUX - Exception in thread "main" java.lang.NoSuchFieldError: LINUX 线程“ main”中的异常java.lang.NoSuchFieldError:VERSION_5 - Exception in thread “main” java.lang.NoSuchFieldError: VERSION_5 线程“ main”中的异常java.lang.NoSuchFieldError:ruleMemo - Exception in thread “main” java.lang.NoSuchFieldError: ruleMemo 线程“ main”中的异常java.lang.NoSuchFieldError:如果可能 - Exception in thread “main” java.lang.NoSuchFieldError: ifpossible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM