SemperFly
SemperFly

Reputation: 1583

Getting a NoClassDefFoundError Exception after adding external .java and .class files

Pardon any mistakes I make in nomenclature as I'm relatively new to Eclipse and Java.

I'm writing an Android app that implements an external API (Amazon Web Service API). The downloaded API files include a directory containing .class files and a directory containing .java files.

In adding these as dependencies, I have done the following:

  1. Eclipse->project properties->java build path->source->link source->Select directory that contains .java files.

  2. Eclipse->project properties->java build path->libraries->add external class folder->Select directory that contains .class files.

At compile time under this configuration, I get the following error:

    java.lang.IllegalArgumentException: already added: Lcom/ECS/client/jax/VariationSummary;
    Conversion to Dalvik format failed with error 1

The error is repeated once for every class file.

To troubleshoot this I removed the reference to the external class folder and the program compiles and runs. Upon reaching the code segment that utilizes one of the API's methods, however, I get a crash with the following error:

01-15 15:29:20.756: E/AndroidRuntime(1038): java.lang.NoClassDefFoundError: com.ECS.client.jax.AWSECommerceService

EDIT

Full stack trace:

01-15 17:12:28.256: W/dalvikvm(1227): Unable to resolve superclass of Lcom/ECS/client/jax/AWSECommerceService; (365)
01-15 17:12:28.296: W/dalvikvm(1227): Link of class 'Lcom/ECS/client/jax/AWSECommerceService;' failed
01-15 17:12:28.296: E/dalvikvm(1227): Could not find class 'com.ECS.client.jax.AWSECommerceService', referenced from method com.giftme.Amazon.searchRequest
01-15 17:12:28.296: W/dalvikvm(1227): VFY: unable to resolve new-instance 66 (Lcom/ECS/client/jax/AWSECommerceService;) in Lcom/giftme/Amazon;
01-15 17:12:28.306: D/dalvikvm(1227): VFY: replacing opcode 0x22 at 0x0000
01-15 17:12:28.306: D/dalvikvm(1227): VFY: dead code 0x0002-0033 in Lcom/giftme/Amazon;.searchRequest (Ljava/lang/String;)Z
01-15 17:12:28.306: W/dalvikvm(1227): threadid=10: thread exiting with uncaught exception (group=0x40015560)

01-15 17:12:28.306: E/AndroidRuntime(1227): FATAL EXCEPTION: Thread-13
01-15 17:12:28.306: E/AndroidRuntime(1227): java.lang.NoClassDefFoundError: com.ECS.client.jax.AWSECommerceService
01-15 17:12:28.306: E/AndroidRuntime(1227):     at com.giftme.Amazon.searchRequest(Amazon.java:21)
01-15 17:12:28.306: E/AndroidRuntime(1227):     at com.giftme.Friend$InterestsRequestListener$4.parseDataAndSearch(Friend.java:359)
01-15 17:12:28.306: E/AndroidRuntime(1227):     at com.giftme.Friend$InterestsRequestListener$4.run(Friend.java:329)
01-15 17:12:28.306: E/AndroidRuntime(1227):     at java.lang.Thread.run(Thread.java:1019)

and here's the line 21 it's referring to:

AWSECommerceService service = new AWSECommerceService();

Upvotes: 0

Views: 678

Answers (1)

Maarten Bodewes
Maarten Bodewes

Reputation: 93958

First of all, you need to link the root folder of the package file (e.g. /classes/ when the classes folder contains e.g. com/amazon/some/or/the/other.. As the class files contain all the information, you don't need to use the source files.

You can however add the root (again) of the package containing the Java files, so you can look at the source if required. The other advantage of this is that you can see the names of the method arguments as they are not present in the class files. Do this by clicking link source in the "build path" tab libraries after expanding the item for the class folder.

Upvotes: 1

Related Questions