处理 java.lang.NoSuchMethodError 的建议
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12906408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Advice dealing with java.lang.NoSuchMethodError
提问by chafnan
Here is the error I am getting:
这是我得到的错误:
java.lang.NoSuchMethodError: com.Order.getList(Lepo/User;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/util/ArrayList;
After decompiling the classes, I found that there should be a "Ljava/lang/String" as the first parameter. As you can see by the error that parameter is missing. So I decompiled the calling method's class and it does a have a string as the first parameter.
反编译类后,发现第一个参数应该是“Ljava/lang/String”。正如您所看到的错误,参数丢失。所以我反编译了调用方法的类,它确实有一个字符串作为第一个参数。
This is where I am a little confused to what is happening here. The last time this code was modified was 2007 according to the timestamps. This error showed up about a week ago.
这是我对这里发生的事情有点困惑的地方。根据时间戳,此代码最后一次修改是 2007 年。大约一周前出现此错误。
This is a struts app running on JBoss 4.0.0DR3. To my knowledge there has been no software upgrades on the server.
这是一个在 JBoss 4.0.0DR3 上运行的 struts 应用程序。据我所知,服务器上没有软件升级。
I also tried stopping JBoss, deleting all the temp directories and restarting.
我还尝试停止 JBoss,删除所有临时目录并重新启动。
Does anyone have any suggestions to the next step to take?
有没有人对下一步采取任何建议?
Edit:
编辑:
Here is more of the stacktrace
这是更多的堆栈跟踪
java.lang.NoSuchMethodError: com.Order.getList(Lepo/User;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/util/ArrayList;
at com.ViewStatusAction.retrieveList(ViewStatusAction.java:325)
at com.ViewStatusAction.executeAction(ViewStatusAction.java:115)
at com.BaseAction.execute(BaseAction.java:42)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
回答by Stephen C
I'm assuming that both the com.Order
and com.ViewStatusAction
are application code, not 3rd-party code.
我假设com.Order
和com.ViewStatusAction
都是应用程序代码,而不是第 3 方代码。
The exception means that you have a version mismatch of some kind.
异常意味着您有某种版本不匹配。
The
ViewStatusAction
class expects there to be a method inOrder
with this signature:java.util.ArrayList getList(Lepo.User arg0, String arg1, String arg2, String arg3, String arg4)
The
Order
class does not declare a method with that signature. (It may have a different signature, or it may not exist at all.)
该
ViewStatusAction
班预计那里是一个方法Order
与此签名:java.util.ArrayList getList(Lepo.User arg0, String arg1, String arg2, String arg3, String arg4)
本
Order
类不声明与签名的方法。(它可能有不同的签名,也可能根本不存在。)
When you originally compiled ViewStatusAction
, the compiler was able to find that method. However now, the runtime system cannot find it any more. This can only mean that you are using a different version of Order
to the one that your ViewStatusAction
class was compiled against.
当您最初编译 时ViewStatusAction
,编译器能够找到该方法。但是现在,运行时系统再也找不到它了。这只能意味着你使用的是不同版本Order
的一个,你的ViewStatusAction
类是针对编译。
You need to find out why you've now got this mismatch. Possible explanations include:
您需要找出现在出现这种不匹配的原因。可能的解释包括:
You have deployed a new version of one of the classes without deploying the new version of the other.
You have deployed an out of date version of one of the classes.
You have two versions of one or other of the classes on your class path and you have unwittingly changed the classpath search order.
您已经部署了其中一个类的新版本,而没有部署另一个类的新版本。
您已经部署了其中一个类的过时版本。
您的类路径上有一个或其他类的两个版本,并且您无意中更改了类路径搜索顺序。
What you need to do is find out where the incompatible classes are coming from, and how they got there. Once you have figured that out, the fix is likely to be self evident.
您需要做的是找出不兼容的类来自哪里,以及它们是如何到达那里的。一旦你弄清楚了,修复很可能是不言而喻的。
I note that your FQ class names doen't conform to accepted standards:
我注意到您的 FQ 类名称不符合公认的标准:
- The package names should start with your organisation's domain name, reversed. "com." is wrong.
- The package names should be all lower-case. "Lepo" is wrong if it is a package name, and if it is a class in the default package, then that is wrong too.
- 包名称应以您组织的域名开头,颠倒。“com。” 是错的。
- 包名称应全部小写。“lepo”如果是包名是错误的,如果是默认包中的类也是错误的。
(It is possible that your problem might be a fall-out of fixing the bogus Lepo.User
name ...)
(您的问题可能是由于修复了虚假Lepo.User
名称而引起的……)
回答by hgh
Probably the runtime jar is different from the jar you use to compile your code. You may also have multiple jars on the classpath containing the same class and shadowing each other. You may want to check your app server runtime classpath, and the jar ordering.
运行时 jar 可能与您用来编译代码的 jar 不同。您还可能在类路径上有多个 jar 包含相同的类并相互遮蔽。您可能需要检查您的应用服务器运行时类路径和 jar 顺序。