java.lang.RuntimeException: Stub!

本文介绍了一个常见的JUnit测试错误“RuntimeException: Stub!”及其解决方案。错误发生在尝试运行测试套件时,并指向了代码中的第八行。文章提供了调整Eclipse中项目构建路径顺序的方法来解决这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I recently tried to run my junit tests to ensure that I didn’t break anything after monkeying around with my code, and I ran into the following error:

1
Exception in thread "main" java.lang.RuntimeException: Stub!

Here’s my code that runs my tests:

1
2
3
4
5
6
7
8
9
10
11
12
13
public class RunTestSuite {
public static void main(String[] a) {
TestRunner.run(suite());
}
 
public static Test suite() {
 
TestSuite suite = new TestSuite();
suite.addTestSuite(MyClassTests. class );
return suite;
}
 
}

The stack trace pointed to line 8, so I didn’t know what to make of it since I just had this setup correctly, and TestSuite is a JUnit thing.

Googling mostly resulted in issues with using an Android Test Project (I’m not) and running the tests in your desktop’s JVM instead of the actual device’s (see here).

Eventually, though, I found this post that informed me that the JUnit library needs to be at the top of the test project’s build order.

Here are the steps to change the build order in Eclipse:

  1. Right-click your test project
  2. Click Bulid Path->Configure Build Path…
  3. Click the Order and Export tab
  4. Select the JUnit reference
  5. Click the Top button
通过把android.jar调整到bottom似乎有用

机器分析结论: 应用名:健康 应用版本号: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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值