添加外部 .java 和 .class 文件后出现 NoClassDefFoundError 异常

发布于 2024-12-27 04:42:24 字数 2444 浏览 1 评论 0原文

请原谅我在命名法中犯的任何错误,因为我对 Eclipse 和 Java 还比较陌生。

我正在编写一个实现外部 API(Amazon Web Service API)的 Android 应用程序。下载的API文件包括一个包含.class文件的目录和一个包含.java文件的目录。

在将这些添加为依赖项时,我执行了以下操作:

  1. Eclipse->项目属性->java 构建路径->源->链接源->选择包含 .java 文件的目录。

  2. Eclipse->项目属性->java构建路径->库->添加外部类文件夹->选择包含.class文件的目录。

在此配置下编译时,我收到以下错误:

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

每个类文件都会重复一次该错误。

为了解决这个问题,我删除了对外部类文件夹的引用,并且程序编译并运行。然而,在到达利用 API 方法之一的代码段时,我遇到崩溃并出现以下错误:

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

编辑

完整堆栈跟踪:

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)

这是它引用的第 21 行到:

AWSECommerceService service = new AWSECommerceService();

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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不打扰别人 2025-01-03 04:42:24

首先,您需要链接包文件的根文件夹(例如/classes/,当类文件夹包含例如com/amazon/some/or/the/other..由于类文件包含所有信息,您不需要 但是,您不需要使用源文件。

您可以(再次)添加包含 Java 文件的包的根目录,这样您就可以在需要时查看源文件。这样做的另一个优点是您可以看到文件的名称。方法参数存在在类文件中,通过在展开类文件夹的项目后单击“构建路径”选项卡库中的链接源来执行此操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文