Eclipse 在运行时抛出 ExceptionInInitializerError ,在调试时抛出 NoClassDefFoundError
项目 A 依赖于项目 B。
在编译时,一切正常。
在调试时,当调用项目 B 的类 bClass 的静态函数时,我得到 NoClassDefFoundError 。
在运行时,我得到 ExceptionInInitializerError。
此外,bClass 有一个静态初始化程序,当我在那里放置一个断点时,它永远不会到达它 - 这对我来说似乎很奇怪,但也有道理,因为该类可能找不到。
知道如何修复吗?我已尽我所能检查了所有依赖项。
Project A depends on project B.
On compilation time , everything is OK.
On debug , when a static function from class bClass of project B is called , I get NoClassDefFoundError .
On run , I get ExceptionInInitializerError.
Besides , the bClass has a static initializer , and when I put a break point there , it never reaches it - which seems very strange to me , but also makes sense because the class is probably not found.
Any idea how to fix? I've checked all dependencies to the best of my understanding.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果出现 NoClassDefFound 异常,请根据编译时类路径仔细检查运行时类路径。 Eclipse 通常使用运行时 CP 的编译时类路径,但如果您修改了默认启动配置,它们可能不再匹配。
In the case of NoClassDefFound exceptions, double check your runtime classpath against your compiletime classpath. Eclipse usually uses the compile-time classpath for the runtime CP but if you have modified the default launch config, they may not match anymore.
我经常发现,如果静态初始化程序抛出异常,那么您会得到这些令人困惑和误导的结果。试试这个:在静态初始化程序中的所有代码周围放置一个 try/catch 语句,并在 catch 块中记录异常(在错误日志中或控制台中)。如果抛出异常,这将帮助您缩小范围。
完成调试后,您应该删除此 try/catch 子句,因为它会吞掉异常。
I've often found that if a static initializer throws an exception, then you get these sorts of confusing and misleading results. Try this: Put a try/catch statement around all of the code that is in the static initializer, and in the catch block, log the exception (in the error log or to the console). If there is an exception that's being thrown, this will help you narrow it down.
When you're done debugging, you should remove this try/catch clause, because it swallows the exception.