eclipse Android - 无法解析超类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12270493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android - Unable to resolve superclass
提问by rhinds
I have dug out an old android project that I was working on a few years ago and loaded it into a new eclipse install (latest ADT etc).
我挖出了几年前我正在做的一个旧的 android 项目,并将它加载到一个新的 eclipse 安装中(最新的 ADT 等)。
The project all compiles ok (after some minor tweaking), and the app starts fine, however, when i press a button to start the main activity i get the following stack trace:
项目全部编译正常(经过一些小调整),应用程序启动正常,但是,当我按下按钮启动主要活动时,我得到以下堆栈跟踪:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.tmm.android.activities.GameActivity
at com.tmm.android.activities.StartActivity.onClick(StartActivity.java:53)
at android.view.View.performClick(View.java:2408)
Now the class in question (GameActivity) is one of my classes that is in the app, so I know thats not the problem - but I noticed a warning right at the top of the logcat:
现在有问题的类(GameActivity)是我在应用程序中的类之一,所以我知道这不是问题 - 但我注意到 logcat 顶部有一个警告:
Unable to resolve superclass of Lcom/tmm/android/activities/GameActivity; (33)
Link of class 'Lcom/tmm/android/activities/GameActivity;' failed
My class GameActivity extends another class that is part of a third-party jar that i have included in the project (included it in the 'libs' directory, and added it to the project build path in eclipse).
我的类 GameActivity 扩展了另一个类,该类是我已包含在项目中的第三方 jar 的一部分(将其包含在“libs”目录中,并将其添加到 eclipse 中的项目构建路径中)。
Can anyone advise what I might have done wrong, or anything that has changed in the ADT/etc that I might need to take account of (it was working fine when i last had it in Eclipse)
任何人都可以建议我可能做错了什么,或者我可能需要考虑的 ADT/etc 中发生的任何变化(当我上次在 Eclipse 中使用它时它工作正常)
Cheers
干杯
采纳答案by rhinds
Ok, was a simple problem in the end..
好吧,最后是一个简单的问题..
Having added the 3rd party library to the build path, the export tab wasnt defaulted to export the jar (eclipse normal behaviour) - so the jar wasnt being included in the deployment..
将第 3 方库添加到构建路径后,导出选项卡并未默认导出 jar(eclipse 正常行为)-因此 jar 未包含在部署中..
got past that problem ok..
解决了这个问题,好吧..
回答by Paul LeBeau
I had the same problem. I had a custom View class which called methods in an imported library. I was also getting the "Unable to resolve superclass" error when the app was trying to create my view (while trying to inflate a layout that referred to that custom View).
我有同样的问题。我有一个自定义 View 类,它在导入的库中调用方法。当应用程序尝试创建我的视图时(同时尝试扩展引用该自定义视图的布局),我也收到了“无法解析超类”错误。
I resolved my problem, and I had a play around to determine what I think is the definitive answer.
我解决了我的问题,并尝试确定我认为的最终答案。
(As at writing, I am using the Eclipse Android Tools R21).
(在撰写本文时,我使用的是 Eclipse Android Tools R21)。
If you are using an external jar
如果您使用的是外部罐子
- Copy it to your project's "libs" folder. The Android Tools should do the rest.
- 将其复制到项目的“libs”文件夹中。Android 工具应该完成剩下的工作。
If the library you want to use is a separate project in your workspace.
如果要使用的库是工作区中的单独项目。
- In your library project: go into Properties->Android and check the "Is Library" checkbox.
- In your app project: go into to Properties->Android and add the library project in the same section there (click "Add.."). Don't check "Is Library" here!
- 在您的库项目中:进入 Properties->Android 并选中“Is Library”复选框。
- 在您的应用项目中:进入 Properties->Android 并在同一部分中添加库项目(单击“Add..”)。不要在这里检查“是图书馆”!
Some answers to this question say you need to go to Properties->Java Build Path->Projects and add the library project there. For normal Java projects you would do that, but it appears the Android Tools don't need or use that.
这个问题的一些答案说您需要转到 Properties->Java Build Path->Projects 并在那里添加库项目。对于普通的 Java 项目,您会这样做,但 Android 工具似乎不需要或使用它。
Finally, you will probably want to make sure the lib is included in your exported app
最后,您可能希望确保该库包含在您导出的应用程序中
- Go to Properties->Java Build Path->Order and Export and make sure the library is checked.
- 转到 Properties->Java Build Path->Order and Export 并确保检查了库。
回答by DenninDalke
I had the same problem, I tried to check the Android Private Libraries under Order and Export and it didn't work for me. So then I noticed that my libs folder wasn't referenced under the Java Build Path, I just added it to Libraries and that is it...
我遇到了同样的问题,我尝试检查 Order 和 Export 下的 Android Private Libraries,但它对我不起作用。然后我注意到我的 libs 文件夹没有在 Java Build Path 下引用,我只是将它添加到 Libraries 中,就是这样......