引用 .jar 库时无法解决超类错误
- 我做了一个Android项目并运行它。它运行成功了。
- 我用 Java 开发了一个 Web 服务并托管它。它运行成功了。
- 我将 Web 服务导出到 .jar 并将其添加到我的 Android 项目中。
- 当我尝试调用 Web 服务中的方法时,出现
无法解析超类
错误。
我的错误日志:
Unable to resolve superclass of Lweb/service/RandomWordGeneratorService; (73)
Link of class 'Lweb/service/RandomWordGeneratorService;' failed
Could not find class 'web.service.RandomWordGeneratorService',
referenced from method tam.miru.Login$1.onClick
VFY: unable to resolve new-instance 110 Lweb/service/RandomWordGeneratorService;)
in Ltam/miru/Login$1;
VFY: replacing opcode 0x22 at 0x005a
VFY: dead code 0x005c-006e in Ltam/miru/Login$1;.onClick (Landroid/view/View;)
- I did an Android project and run it. It ran successfully.
- I developed a web service in Java and hosted it. It ran successfully.
- I exported the webservice into a .jar and added it to my Android project.
- When I try to call a method in the web service I get an
Unable to resolve superclass
error.
My error log:
Unable to resolve superclass of Lweb/service/RandomWordGeneratorService; (73)
Link of class 'Lweb/service/RandomWordGeneratorService;' failed
Could not find class 'web.service.RandomWordGeneratorService',
referenced from method tam.miru.Login$1.onClick
VFY: unable to resolve new-instance 110 Lweb/service/RandomWordGeneratorService;)
in Ltam/miru/Login$1;
VFY: replacing opcode 0x22 at 0x005a
VFY: dead code 0x005c-006e in Ltam/miru/Login$1;.onClick (Landroid/view/View;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
升级到 ADT 17 后才开始遇到此问题。
发现外部 .jar 文件需要位于“libs”(带 s)文件夹中,否则它们的类不会包含在创建的 .dex 文件中。升级之前,“lib”文件夹中的 .jar 文件一切正常(无 s)。
Just started to get this issue after upgrading to ADT 17.
Discovered that external .jar files need to be in a 'libs' (with an s) folder otherwise their classes are not included in the .dex file that is created. Before the upgrade everything worked fine with my .jar files in a 'lib' folder (no s).
就我而言,我必须进入
Properties->Java Build Path->Order and Export
并检查Android Private Libraries
,然后清理项目并正常工作。In my case I had to go to
Properties->Java Build Path->Order and Export
and checkAndroid Private Libraries
, then cleaned the project and worked fine.创建lib文件夹,libs文件夹用于存放本机库。我做到了,将库添加到 lib 并将路径构建为内部库,它可以工作!
Create lib folder, libs folder is for native libraries. I made it, add library to lib and to build path as internal library and it works!
你用的是eclipse吗?如果是这样,您是否按照 向 Eclipse Android 项目添加库/JAR?
Are you using eclipse? If so, did you add the library to the build path as described in Adding a library/JAR to an Eclipse Android project?
我知道这是一篇关于非常旧的线程的帖子,但是在我阅读@rabidgremlin 的答案后,我检查了文件夹结构,发现它已经在“libs”中。然而,在看到 support.jar 后,我认为使用它是导致问题的原因。
我正在扩展“FragmentActivity”,但事实证明,它引用了 support.jar,它本身就有问题。一旦我删除了扩展子句,应用程序就奇迹般地停止了崩溃。
仅供参考,以防有人来看。干杯!
I know that this a post on a really old thread, but after I read the answer by @rabidgremlin, I checked the folder structure, and found that it was already in "libs". However, on seeing the support.jar, I figured that using this was what was causing the issue.
I was extending "FragmentActivity" but it turns out, that was referencing the support.jar, which had issues in itself. Once I removed the extends clause, the app miraculously stopped crashing.
Just an FYI in case someone comes looking. Cheers!
我遇到了同样的问题,我尝试在“订购”和“导出”下标记 Android 私人库,但它对我不起作用。然后我注意到 Java 构建路径下没有引用我的 libs 文件夹。所以我只是将它添加到库中并且它起作用了。
I had the same problem, I tried to mark the Android Private Libraries under Order and Export and it didn't work for me. Then I noticed that my libs folder wasn't referenced under the Java Build Path. So I just added it to Libraries and it worked.
我有同样的错误消息。我花了一些时间才弄清楚问题:Android 需要 Java 1.6 才能工作。我的 Activity 的超类实现了一个来自 Java 项目的接口,该项目以 Java 1.7 作为编译器。这足以让 dex 构建器无法链接超类,从而导致类未找到异常。
I had the same error message. Took me some time to figure out the problem: Android requires Java 1.6 to work. And the superclass of my Activity implemented an interface from a Java project that had Java 1.7 as compiler. That was enough for the dex builder not to be able to link the superclass and this resulted in the class not found exception.
我在 Eclipse 上遇到了导致此错误的不同原因。我正在尝试将 Eclipse 工作区放入 google 驱动器目录中,发现某些超类无法从 android 活动中解析。
暂停了谷歌驱动器,一切开始正常工作。就我而言,无法加载的超类来自协议缓冲区生成的类。这个类和我测试的所有其他类在非 Android java 程序中都运行良好,即使在 google Drive 正在运行时也是如此。
I ran into a different cause for this error on Eclipse. I was experimenting with putting eclipse workspaces into google drive directories and discovered that certain superclasses can't be resolved from android activities.
Paused google drive and everything began working fine. In my case the superclass that wouldn't load was from a protocol buffers generated class. This class and all others I tested worked fine in non-android java programs, even while google drive was running.