java.lang.NoClassDefFoundError - 为什么?如何排除故障?
我的应用程序中的一个菜单项只是尝试调用另一个活动(属于同一工作区中的不同项目):
myActivity.startActivity(new Intent(myActivity, com.bill.the.App.class));
但这会立即导致运行时出现异常:
E/AndroidRuntime(3847): java.lang.NoClassDefFoundError: com.bill.the.App
为什么?
我缺少什么?
(项目编译和构建都很好,只是在运行时才会出现此错误)
One of my menu items in my application simply tries to invoke another activity (that belongs to a different project in the same workspace):
myActivity.startActivity(new Intent(myActivity, com.bill.the.App.class));
But that immediately results in an exception at runtime:
E/AndroidRuntime(3847): java.lang.NoClassDefFoundError: com.bill.the.App
Why?
What am I missing?
(the project compiles and build just fine, it's only at run time that this error occurs)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
包含 com.bill.the.App 的项目或库可能包含在编译搜索路径中,但不包含在生成的 apk 文件(部署到设备)中。如果您使用错误的方式包含包含 com.bill.the.App 的项目或库,则可能会发生这种情况。确保通过使用 Android Library Project(项目属性 -> Android)或在项目属性 -> Android 中包含 jar 文件来包含它。 Java 构建路径 ->图书馆。
It could be that the project or library containing com.bill.the.App is included in compilation search path, but not included in the resulting apk file (that is deployed to the device). If you include the project or library containing com.bill.the.App using a wrong way, this can happen. Make sure that you include it by using Android Library Project (project properties -> Android) or by including the jar file in the project properties -> Java Build Path -> Libraries.
只需打开
AndroidManiFest.xml
,然后在标记之前写入以下行。
Just Open your
AndroidManiFest.xml
, and write following line in it before the</application>
tag.将旧的 Eclipse/ADT 项目(由多个项目 AKA 模块组成)导入到 Android Studio (2021.3.1.17) 时,我遇到了同样的问题。
解决方案是右键单击应用程序的模块>
打开模块设置
>依赖关系
> (应用程序的模块)>+
(添加依赖项)>3 模块依赖
>选择包含缺少的类的模块/项目。I had the same problem when importing an old Eclipse/ADT project (made of several projects AKA modules) to Android Studio (2021.3.1.17).
The solution was to right-click the app's module >
Open Module Settings
>Dependencies
> (app's module) >+
(Add Dependency) >3 Module Dependency
> Select the module/project that contains the missing class.该活动可能未在清单中注册
The activity may not be registered in the manifest