2015-01-07 63 views
3

我正在嘗試使用Unirest-Mashape來構建Java應用程序。java.lang.NoClassDefFoundError:org/apache/http/concurrent/FutureCallback

這是我的代碼:

import com.mashape.unirest.http.*; 
public class PAskMe 
{ 
    public static void main(String args[]) throws Exception 
    { 
     HttpResponse<JsonNode> response = Unirest.get("https://montanaflynn-dictionary.p.mashape.com/define?word=irony"). 
                       header("X-Mashape-Key", "UgVSX18IyimshpgKhzWe86s9h2lLp1XZze9jsnvGkwfubVFHUL"). 
                       asJson(); 
     System.out.println(response.toString()); 
    } 
} 

當我編譯我的代碼,這表明沒有錯誤。但是,當我運行它,它顯示了以下運行時錯誤:

java.lang.NoClassDefFoundError: org/apache/http/concurrent/FutureCallback 
at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68) 
at PAskMe.PAskMe.main(PAskMe.java:14) 
at PAskMe.__SHELL0.run(__SHELL0.java:6) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at bluej.runtime.ExecServer$3.run(ExecServer.java:725) 

Caused by: java.lang.ClassNotFoundException: org.apache.http.concurrent.FutureCallback 
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:423) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:356) 
... 8 more 

我已經包括在我的項目,這些罐子:

I have included these jars in my project

但我仍正在錯誤。請幫幫我。

回答

8

下載httpcore-4.2.3.jar並將其添加到您的類路徑中。

+0

我這樣做。但仍然有同樣的錯誤。 – Hackerdarshi

+0

@PriydarshiSingh你使用了哪個版本的'httpcore.jar'? – Jens

+0

文件名是** httpcore-4.0-alpha6.jar ** – Hackerdarshi