NoSuchMethodErrors 说出了最可怕的事情

发布于 2024-09-05 04:40:08 字数 275 浏览 6 评论 0原文

所以,我正在 Eclipse 中工作,一切都正确编译和运行。然而,当在构建服务器的 ant 下编译时,大量测试失败,并出现 NoSuchMethodError 错误:

class A Implements B
接口 B 扩展 C
C 需要方法 getSyncID() // int 字段的标准 getter。
A.java包含getSyncID()
A.class 包含 getSyncID()

但仍然抛出错误。

有谁知道这到底是怎么发生的?如何修复它。

So, I'm working in eclipse were everything compiles and runs correctly. However, when compiling under ant for the build server, A large number of tests fail with a NoSuchMethodError saying:

class A implements B
interface B extends C
C requires method getSyncID() // standard getter for an int field.
A.java contains getSyncID()
A.class contains getSyncID()

and yet the Error is still thrown.

Does anyone know how the hell this could happen? how to fix it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁的新欢旧爱 2024-09-12 04:40:08

当类文件彼此不同步时,就会发生这种情况;换句话说,一个被编译为新版本,而另一个则没有。尝试从头开始清理和重建。

This happens when class files get out of sync with each other; in other words, one was compiled to a new version while another one wasn't. Try cleaning and rebuilding from scratch.

冰之心 2024-09-12 04:40:08

当类加载器发现一个类 (A) 中的方法调用另一个类 (B) 中不存在的方法时,就会出现问题。根本原因是类加载器看到的类 B 与编译器在编译 A 时看到的类 B 不同。

这个问题的最常见原因是@MarkPeters 所说的 - 你的“.class”文件已经得到了与“.java”文件不同步,需要从头开始重新编译。

另一种可能性是,当您尝试运行应用程序时,类路径上有一些“.class”文件的旧副本。

但无论哪种方式,你都必须相信类加载器。如果它说该方法不存在,那么它不存在 ... 在它正在加载的特定“.class”文件中。如果该方法出现在“.class”文件中,则表明您正在类路径中较早加载该文件的不同版本!

The problem occurs when the class loader discovers that a method in one class (A) calls a method in another class (B) that does not exist. The root cause is that the class B that the class loader sees is different to the class B that the compiler saw when it compiled A.

The most common cause of this problem is as @MarkPeters says - that your ".class" files have gotten out of sync with the ".java" files and need to be recompiled from scratch.

Another possibility is that you have an old copy of some of the ".class" files on the classpath when you try to run the application.

But either way, you have to believe the classloader. If it says that the method is not there, then it is not there ... in the particular ".class" file that it is loading. If the method appears to be there in the ".class" file, then that is evidence that you are loading a different version of the file earlier in the classpath!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文