1

I'm building an application using Mashape's Unirest library(unirest-java-1.2.6.jar) . I'm getting NoClassDefFoundError during runtime. I tried CommonsWare's method. But it didn't work. Here is the screenshot of Java Build Path. Anything wrong in this screenshot??

enter image description here

Community
  • 1
  • 1
DroidLearner
  • 2,115
  • 5
  • 31
  • 50

3 Answers3

6

I'm the author of Unirest-Java.

In order to use the library, you need to include the required dependencies into your project:

  • Apache HttpComponents Client
  • Apache HttpComponents AsyncClient
  • Apache HttpComponents Mime
  • JSON library

Using Maven is the preferred method: https://github.com/Mashape/unirest-java#installing

Otherwise the libraries can be manually downloaded from http://hc.apache.org/downloads.cgi and http://www.json.org/java/index.html

But again, I would strongly recommend to use Maven. Also please update the Unirest library to the newest version because 1.2.6 is deprecated now.

Mark
  • 67,098
  • 47
  • 117
  • 162
  • I tried installing using maven plugin for eclipse . I created `pom.xml` file with your contents http://gist.github.com/thefosk/7325187. I did `Maven Install` by right clicking `pom.xml`and it generates a folder named `target` contains set of files with snapshot.jar file. You can see the screenshot here http://i41.tinypic.com/27y8q39.jpg And while creating a request it shows error. How to import Unirest? – DroidLearner Nov 06 '13 at 08:13
  • 1
    After you import the library in your project, you also need to import the dependency in your source file. Can you add this code before "public class [..]": https://gist.github.com/thefosk/7343991 – Mark Nov 06 '13 at 21:00
  • I meant to say that except Unirest other files are being imported using Maven. It created Snapshot.jar file in android project. Please see this screenshot http://i.imgur.com/auHM1SX.jpg – DroidLearner Nov 08 '13 at 05:57
0

It's advisable to package everything in one uber jar by using Maven.

Please refer to this post on how to use Unirest in your Java projects.

Chris Ismael
  • 612
  • 5
  • 13
  • 14
0

This probably won't apply to many folks, but I was getting this error because I had an errant jar being bundled by gradle. It was a fat jar dependency that included unirest, was being stored in the codebase, and was not listed explicitly - instead, it was getting bundled with the gradle statement:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
}
Greg
  • 2,476
  • 4
  • 22
  • 28