如何放心解决 java.lang.java.lang.NoSuchFieldError:DEF_CONTENT_CHARSET? [英] How to resolve java.lang.java.lang.NoSuchFieldError:DEF_CONTENT_CHARSET in rest assured?
问题描述
我是初学者,正在尝试检查给定 url 的响应.我写了一个非常简单的代码,但收到一个异常.我已经尝试了很多事情,但我无法解决它.请帮帮我.
I am a beginner, and am trying to check response for given url. I have written a very simple code, but am recieving an exception. I have tried a lot of things, but I have not been able to resolve it. Please help me.
代码:
public class RestAPITest {
@Test
public void test() {
final String url = "http//:127.0.0.1:8080/myproject/api/";
given().parameter("HEADER_NAME", "X-Auth-Token", "MY_DEFAULT_TOKEN", "_MY_REST_TOKEN").
contentType("application/json; charset=UTF-16").when().get(url).then().statusCode(200);
}
}
发生异常:
java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
at com.jayway.restassured.config.EncoderConfig.<init>(EncoderConfig.java:48)
at com.jayway.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
at com.jayway.restassured.RestAssured.<clinit>(RestAssured.java:423)
at com.rest.RestAPITest.test(RestAPITest.java:59)
推荐答案
这似乎是一个依赖问题.请参阅官方问题跟踪器上的此主题.
It seems to be a dependency issue. See this thread on the official issues tracker.
我遇到了同样的错误并通过更改 httpcore
版本解决了它.该库在我的类路径中,作为全局依赖项下载,但它是 4.0.1 版.我猜最低要求是 4.4.x.
I had the same error and solved it by changing the httpcore
version. The library was in my classpath, downloaded as global dependency but it was the version 4.0.1. I guess the minimal requirement is 4.4.x.
在项目设置中,我删除了httpcore
的4.0.1版本.我使用Maven下载了4.4.6版本并添加到项目中.
In the project settings, I removed the version 4.0.1 of httpcore
. I downloaded the version 4.4.6 using Maven and added it to the project.
这篇关于如何放心解决 java.lang.java.lang.NoSuchFieldError:DEF_CONTENT_CHARSET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!