AndroidRuntime: java.lang.NoClassDefFoundError 错误的解决办法

本文汇总了解决Java开发中遇到的NoClassDefFoundError异常的方法,包括调整类路径设置、正确配置第三方库及解决版本迁移问题。

先找来几篇类似问题的解决办法:

1.看错误是类没有找到,但是代码中确实有这个类,编译没错,执行的时候报这个异常。

我同事的机器没事,我的有问题。

想了一下差别,就是.classPath文件不一致。

后来进 project - properties-java build path - Order and Export,试着调了一下顺序,

工程名/gen工程名/src之上,问题居然解决了。


2.首先声明在升级之前我运行的工程是好的是可以运行的
我将工程导入Eclipse发现无法运行报 java.lang.NoClassDefFoundError错误 并且AndroidManifest.xml也注册了该类。
后来发现_5L1NR_U`%_H__FV_GN{RR3.jpg
折腾了好久
这里必须把Android Private Libraries选上注意只要选这个其他不能动的
好了就这样总之我的问题能解决。


3.

在使用百度定位SDK时发生这种问题:java.lang.NoClassDefFoundError: com.baidu.location.LocationClient 

问题出错过程:

工程原来是在R12版本下开发的,后来为了追风,我就换掉R12,改成使用R21.1了。然后从svn上检出R12版本下开发的代码(这个代码在R12下运行是完全没有错误的)。问题就来了,一旦运行代码,就报java.lang.NoClassDefFoundError。


第一次报的是我继承的BDLocationListener的Listener找不到,private class MyBDListener implements BDLocationListener 。我认为是在打包代码的时候出现问题,于是我就不使用继承直接在LocationClient.registerLocationListener(new BDLocationListener(){}),直接做了个内部类。这样果然不在包找不到Listener的错误了。但是接着就又报错:java.lang.NoClassDefFoundError: com.baidu.location.LocationClient。稍微分析一下,就觉得这不是我自己代码问题了,是第三方jar包问题啊,首先想到的是:是不是混淆的时候将其混淆了,然后就找不到这个类了?于是在proguard.cfg中添加配置如下:-keep class com.baidu.**{*;} 这样就不混淆了吧。于是再次运行,还是报同样的错误。排除混淆错误后,就真没遇到过这样的问题了,然后百度了下,有人也遇到这个问题了,他使用的R16,将lib改成libs就没问题了,但是我的工程中,jar明明就是在libs文件下!而且代码在之前的版本都能正常运行,在高版本下就不行了,肯定不是代码问题,必须是环境问题啊。经验这样告诉我。既然觉得是环境问题就肯定是高低版本区别之处出问题了,于是想当然的想到了bin目录,打开之后果然发现有几个隐藏颇深的红色×。想都没想,果断删之。如果你是在eclipse中删除的话,他只是删除了里面的几个文件,根本没有删除干净,红×照样在眼前。为了彻底删除,关闭eclipse,然后通过资源管理器找到该bin然后删除,重新打开eclipse,一般等eclipse刷新加载编译完毕应该就没错了。但是我的还是报错,于是就clean下工程,然后红色×就不见了。既然不见了,说明就没问题了呗。于是重新运行工程,错误果断没有了,成功进入主界面。


总结类似找不到第三方jar中class的解决办法:

1、如果你是R16版本,并且你的jar还是lib文件下,那么你先将lib rename为libs,然后clear工程试试还有没有问题
2、如果还不成功,你可以试探着将第三方的混淆给去掉,有些时候,就是因为混淆了第三方的代码,导致找不到第三方的类。在proguard.cfg文件中添加配置 例如:-keep class com.baidu.**{*;}
3、如果你是从低版本转移到高版本,出现某些不可思议的问题,比如在低版本正常运行的代码,在高版本中出错了,你稍微从高低版本的不同处找一下原因。比如我:删除bin然后让他自动生成下。然后的然后就没问题了。
4、如果你跟我上次遇到的问题一样,类找到了,但是发现类中的某个方法找不到,那么,你就考虑下是不是冲突问题,改一下你类的包名。(这中问题一般出现在开源代码生成的jar中,不常见)。


4.现在是我这个问题,我是在导入人人SDKdemo的时候运行报这个错误的:

我的解决办法是把那2个jar包勾选!!不知道从什么时候开始多了个Android Private Libraries

有了这个在添加jar包的时候就不用add to build了。。



机器分析结论: 应用名:健康 应用版本号:4.20.34_b780cda_250217 安装路径:null安装 应用进程名:com.heytap.health:SportDaemonService 问题类型:JavaCrash 问题原因:java.lang.NoClassDefFoundError错误 结果匹配:相关 关键日志: Line 5304: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: java.lang.NoClassDefFoundError: sf.b Line 5312: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: Caused by: java.lang.ExceptionInInitializerError Line 5323: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: Caused by: java.lang.RuntimeException: stub 堆栈信息: Line 5302: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: FATAL EXCEPTION: ES@DP_SyncCloud Line 5303: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: Process: com.heytap.health:SportDaemonService, PID: 22556 Line 5304: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: java.lang.NoClassDefFoundError: sf.b Line 5305: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at com.health.database.depend.d.N(SourceFile:1) Line 5306: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at pb.c.a(SourceFile:54) Line 5307: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at androidx.appcompat.widget.c.run(SourceFile:120) Line 5308: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at kg.a.run(SourceFile:6) Line 5309: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) Line 5310: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) Line 5311: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at java.lang.Thread.run(Thread.java:1012) Line 5312: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: Caused by: java.lang.ExceptionInInitializerError Line 5313: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at qd.a.initAfterPrivacyAgreed(SourceFile:12) Line 5314: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at pd.g.b(Unknown Source:2) Line 5315: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at pd.c.b(SourceFile:5) Line 5316: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at androidx.camera.core.p.run(SourceFile:91) Line 5317: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at kg.a.run(SourceFile:6) Line 5318: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at com.heytap.health.base.task.ThreadUtils$b.run(SourceFile:6) Line 5319: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487) Line 5320: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:264) Line 5321: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:307) Line 5322: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: ... 3 more Line 5323: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: Caused by: java.lang.RuntimeException: stub Line 5324: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at com.oplus.osense.OsenseResEventClient.getInstance(Unknown Source:4) Line 5325: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: at sf.b.<clinit>(SourceFile:5) Line 5326: 03-24 15:40:12.838 22556 23127 E AndroidRuntime: ... 12 more
03-28
12-24 03:56:58.260 8423 9164 E AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-2 12-24 03:56:58.260 8423 9164 E AndroidRuntime: Process: com.oplus.autotest.chargemanualtest, PID: 8423 12-24 03:56:58.260 8423 9164 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/engineer/OplusEngineerManager; 12-24 03:56:58.260 8423 9164 E AndroidRuntime: at com.oppo.autotest.support.tools.at.SystemProperties.setAsSystemServer(SystemProperties.java:76) 12-24 03:56:58.260 8423 9164 E AndroidRuntime: at com.oplus.autotest.common.core.shell.Shell.openPort(Shell.kt:209) 12-24 03:56:58.260 8423 9164 E AndroidRuntime: at com.oplus.autotest.common.core.shell.Shell.access$openPort(Shell.kt:28) 12-24 03:56:58.260 8423 9164 E AndroidRuntime: at com.oplus.autotest.common.core.shell.Shell$waitForInit$2.invokeSuspend(Shell.kt:87) 12-24 03:56:58.260 8423 9164 E AndroidRuntime: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 12-24 03:56:58.260 8423 9164 E AndroidRuntime: at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) 12-24 03:56:58.260 8423 9164 E AndroidRuntime: at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:585) 12-24 03:56:58.260 8423 9164 E AndroidRuntime: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:802) 12-24 03:56:58.260 8423 9164 E AndroidRuntime: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:706) 12-24 03:56:58.260 8423 9164 E AndroidRuntime: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:693) 12-24 03:56:58.260 8423 9164 E AndroidRuntime: Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@c262d8f, Dispatchers.Default] 12-24 03:56:58.260 8423 9164 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: android.engineer.OplusEngineerManager 12-24 03:56:58.260 8423 9164 E AndroidRuntime: ... 10 more
最新发布
12-25
07-26 16:51:12.475 32610 32610 E AndroidRuntime: FATAL EXCEPTION: main 07-26 16:51:12.475 32610 32610 E AndroidRuntime: Process: com.oplus.engineermode, PID: 32610 07-26 16:51:12.475 32610 32610 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/telephony/OplusTelephonyManager; 07-26 16:51:12.475 32610 32610 E AndroidRuntime: at com.oplus.engineermode.command.CustomizeOrderHandler.getOperator(CustomizeOrderHandler.java:134) 07-26 16:51:12.475 32610 32610 E AndroidRuntime: at com.oplus.engineermode.command.CustomizeOrderHandler.handlerOrder(CustomizeOrderHandler.java:70) 07-26 16:51:12.475 32610 32610 E AndroidRuntime: at com.oplus.engineermode.command.EngineerModeOrderHandler.handleMessage(EngineerModeOrderHandler.java:99) 07-26 16:51:12.475 32610 32610 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) 07-26 16:51:12.475 32610 32610 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:205) 07-26 16:51:12.475 32610 32610 E AndroidRuntime: at android.os.Looper.loop(Looper.java:294) 07-26 16:51:12.475 32610 32610 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8256) 07-26 16:51:12.475 32610 32610 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 07-26 16:51:12.475 32610 32610 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:557) 07-26 16:51:12.475 32610 32610 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:993) 07-26 16:51:12.475 32610 32610 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: android.telephony.OplusTelephonyManager 07-26 16:51:12.475 32610 32610 E AndroidRuntime: ... 10 more
07-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值