3

I am trying to use Unirest-Mashape to build java applications.

This is my code:

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", "KEY").
                                                                                asJson();
        System.out.println(response.toString());
  }
}

When I compile my code, It shows no error. But when I run it, it shows the following runtime error :

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 :

I have included these jars in my project

But still I am getting the error. Please help me.

dryairship
  • 6,022
  • 4
  • 28
  • 54

3 Answers3

11

Download httpcore-4.2.3.jar and add it to your classpath.

dryairship
  • 6,022
  • 4
  • 28
  • 54
Jens
  • 67,715
  • 15
  • 98
  • 113
1

a .jar file is missing httpcore-4.2.3.jar

download from http://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore/4.0-alpha6

user3619843
  • 51
  • 1
  • 9
0

Along with httpcore-4.4.12.jar you also need to add below dependencies to avoid runtime error

httpclient-4.5.6.jar

httpmime-4.5.6.jar

also make sure that all dependencies are compatible with each other

hitesh bedre
  • 459
  • 2
  • 11