简体   繁体   English

我项目中的类的Android java.lang.NoClassDefFoundError

[英]Android java.lang.NoClassDefFoundError for class in my project

I am getting below error on initializing the NavigationDrawerRecyclerViewAdapter . 我在初始化NavigationDrawerRecyclerViewAdapter时遇到错误。

Now class com.mypackage.app.NavigationDrawerRecyclerViewAdapter exists and it is public and its constructor is public as well. 现在,类com.mypackage.app.NavigationDrawerRecyclerViewAdapter存在,并且是公共的,其构造函数也是公共的。

1: thread exiting with uncaught exception (group=0x416fed58)
05-18 10:46:20.573 3669-3669/com.mypackage.app E/AndroidRuntime: FATAL EXCEPTION: main Process: com.mypackage.app, PID: 3669
java.lang.NoClassDefFoundError: com.mypackage.app.NavigationDrawerRecyclerViewAdapter                                                                       at com.mypackage.app.FragmentDrawer.onCreateView(FragmentDrawer.java:68)

clean and rebuild project doesn't work. 清理和重建项目无效。 Any suggestions around what could be the problem here? 关于这里可能存在的问题有什么建议吗?

Click on your project -> Properties -> Build Path -> Order and Export Tab. 单击项目->属性->构建路径->订单和导出选项卡。 Make sure that "Android Private Libraries" is checked for Export. 确保已选中“ Android私有库”以进行导出。 If libraries are already adde from the libs/ folder, remove them as they are automatically added in the "Android Private Libraries" section. 如果已经从libs /文件夹添加了库,请删除它们,因为它们会在“ Android Private Libraries”部分中自动添加。

NoClassDefFoundError indicates that class was present during the time of compilation but not available when you run your application, sometimes error on static initializer block can also result in NoClassDefFoundError or context of this class not accessible. NoClassDefFoundError表示该类在编译期间存在,但在运行应用程序时不可用,有时静态初始化程序块上的错误也可能导致NoClassDefFoundError或此类的上下文无法访问。 So, make sure this class refers same class memory. 因此,请确保此类引用相同的类内存。

I found the answer. 我找到了答案。

I had multidex enabled and that was causing the problem. 我启用了multidex,这就是造成问题的原因。 I was using compile 'com.google.android.gms:play-services:8.4.0' in my build.gradle while I needed only com.google.android.gms:play-services-auth:8.4.0. 我只在com.google.android.gms:play-services-auth:8.4.0中使用build.gradle中的compile'c​​om.google.android.gms:play-services:8.4.0'。

Changing the above , I was able to run my application without enabling multidex which was causing class not found error. 更改以上内容后,我能够在不启用导致类未找到错误的multidex的情况下运行我的应用程序。

This helped: App not launching with multidexEnabled true in android studio - Famous 65k reference method 这有助于: 应用程序无法在Android Studio中使用multidexEnabled true启动-著名的65k参考方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM