获取"java.lang.NoClassDefFoundError: org/apache/http/nio/reactor/IOReactorException"

7

我正在尝试使用Mashape API,我已经将以下库(JAR文件)添加到我的项目中:unirest、httpasyncclient、httpclient、httpmime、org.json、commons-longging、httpcore。

我正在尝试运行...

HttpResponse<JsonNode> response = Unirest.post("https://life-left.p.mashape.com/time-left")
.header("X-Mashape-Key", "1NZITOdDGqmshKRAEdDbX0tp0WV2p1RR5SSjsnQYQIVwrANkhC")
.header("Content-Type", "application/x-www-form-urlencoded")
.field("birth", "22 April 1977")
.field("gender", "female")
.asJson();

但是我遇到了这个异常...


Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/nio/reactor/IOReactorException
at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:154)
at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:131)
at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
at test.Test.main(Test.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.http.nio.reactor.IOReactorException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

我尝试过在谷歌上搜索,但仍然无法找到问题所在。

非常感谢您的帮助。


1
你需要在项目库中添加nio api jar。通过链接下载并将其添加到项目库中。 链接 - Altmish-E-Azam
谢谢!那个有效。 - OneTwo
这是HttpCore 4.3.3二进制文件的一部分,您可以从Apache下载。 - Tommy
1个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
9
我曾经遇到过相同的问题,但是在我的项目pom.xml文件中添加以下依赖后,问题得以解决。
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore-nio</artifactId>
        <version>4.4.3</version>
    </dependency>

为什么?因为'httpcore-nio'库应该已经通过'httpasyncclient'库被引用了。 - Saurabh Gupta

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,