songyy
songyy

Reputation: 4573

Android -- include jar cause 'class not found' exception

I want to include Netty's jar into my android project.

I've tried adding it directly as a reference, but I'm getting java.lang.NoClassDefFoundError, pointing to a class from Netty.

Another way is to put the library directly into the libs folder, and when I'm doing so, the Eclipse's Android plugin would automatically include the jars in the libs folder into the 'android private library'. In that case it seems that I cannot attach a source.

I tried deleting the android private library, and link everything through the reference library. It seems that the android cannot find class from reference library; because it's causing the NoClassDefFoundError exception.

I want to know if there're proper ways to solve this problem.

NOTE: I do know that there're lots of posts about this issue.. such as this method (from the link above):

  1. Create a folder called libs in your project's root folder
  2. Copy your JAR files to the libs folder
  3. Now right click on the Jar file and then select Build Path > Add to Build Path, which will create a folder called 'Referenced Libraries' within your project

But it's just causing the NoClassDefFoundError exception.

I'm using Eclipse Kepler.

Upvotes: 1

Views: 1894

Answers (4)

DBK
DBK

Reputation: 1

Above all steps give you same kind of error again and again. Don't be afraid I will solve your problem:

  1. Instead of adding external .jar file, remove it from library.
  2. Copy your driver file into project web-inf/lib(ex.ojdbc14.jar)
  3. Run your dyanamic application.

Upvotes: 0

Sheraz Ahmad Khilji
Sheraz Ahmad Khilji

Reputation: 8358

I think you didn't check the Android Private Libraries. Take a look at this answer

Upvotes: 1

Sergey  Pekar
Sergey Pekar

Reputation: 8745

I solved such issue with the next steps:

  1. Go to Java Build Path->Order And Export
  2. Turn on check box for all libraries
  3. Click OK
  4. Clean and Rebuild your project

Upvotes: 2

BAZTED
BAZTED

Reputation: 546

Try to run Project → Clean(select all projects). It should clean & rebuild everything.

If eclipse haven't imported jar you will have errors in your java files. If your projects are building with no errors and even is trying to start on emulator or device it may be problem of compilatiion. This problem happens often when using gradle. And the best solution is to clean everything and rebuild :)

Upvotes: 0

Related Questions