解释 java.lang.NoSuchMethodError 消息
我收到以下运行时错误消息(以及堆栈跟踪的第一行,它指向第 94 行)。我试图弄清楚为什么它说不存在这样的方法。
java.lang.NoSuchMethodError:
com.sun.tools.doclets.formats.html.SubWriterHolderWriter.printDocLinkForMenu(
ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;
Ljava/lang/String;Z)Ljava/lang/String;
at com.sun.tools.doclets.formats.html.AbstractExecutableMemberWriter.writeSummaryLink(
AbstractExecutableMemberWriter.java:94)
writeSummaryLink 的第 94 行如下所示。
问题
“ILcom”或“Z”是什么意思?
为什么括号里有四种类型 (ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;Ljava/lang/String;Z) 以及括号后的一位 Ljava/lang/字符串; 当方法 printDocLinkForMenu 明显有五个参数时?
代码详细信息
writeSummaryLink 方法是:
protected void writeSummaryLink(int context, ClassDoc cd, ProgramElementDoc member) {
ExecutableMemberDoc emd = (ExecutableMemberDoc)member;
String name = emd.name();
writer.strong();
writer.printDocLinkForMenu(context, cd, (MemberDoc) emd, name, false); // 94
writer.strongEnd();
writer.displayLength = name.length();
writeParameters(emd, false);
}
这是第 94 行调用的方法:
public void printDocLinkForMenu(int context, ClassDoc classDoc, MemberDoc doc,
String label, boolean strong) {
String docLink = getDocLink(context, classDoc, doc, label, strong);
print(deleteParameterAnchors(docLink));
}
I get the following runtime error message (along with the first line of the stack trace, which points to line 94). I'm trying to figure out why it says no such method exists.
java.lang.NoSuchMethodError:
com.sun.tools.doclets.formats.html.SubWriterHolderWriter.printDocLinkForMenu(
ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;
Ljava/lang/String;Z)Ljava/lang/String;
at com.sun.tools.doclets.formats.html.AbstractExecutableMemberWriter.writeSummaryLink(
AbstractExecutableMemberWriter.java:94)
Line 94 of writeSummaryLink is shown below.
QUESTIONS
What does "ILcom" or "Z" mean?
Why there are four types in parentheses
(ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;Ljava/lang/String;Z)
and one after the parentheses
Ljava/lang/String;
when the method printDocLinkForMenu clearly has five parameters?
CODE DETAIL
The writeSummaryLink method is:
protected void writeSummaryLink(int context, ClassDoc cd, ProgramElementDoc member) {
ExecutableMemberDoc emd = (ExecutableMemberDoc)member;
String name = emd.name();
writer.strong();
writer.printDocLinkForMenu(context, cd, (MemberDoc) emd, name, false); // 94
writer.strongEnd();
writer.displayLength = name.length();
writeParameters(emd, false);
}
Here's the method line 94 is calling:
public void printDocLinkForMenu(int context, ClassDoc classDoc, MemberDoc doc,
String label, boolean strong) {
String docLink = getDocLink(context, classDoc, doc, label, strong);
print(deleteParameterAnchors(docLink));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自第 4.3.2 节:
来自 第 4.3.3 节,方法描述符:
因此,
(ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;Ljava/lang/String;Z)
Ljava/lang/String;
转换为:
具有
int
、ClassDoc
、MemberDoc
、String
的方法> 和boolean
作为参数,并返回一个String
。请注意,只有引用参数才用分号分隔,因为分号是其字符表示的一部分。所以,总结一下:
有五个参数(int、ClassDoc、MemberDoc、String、boolean)和一种返回类型(String)。
From section 4.3.2 of the JVM Spec:
From section 4.3.3, Method descriptors:
Thus,
(ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;Ljava/lang/String;Z)
Ljava/lang/String;
translates to:
A method with
int
,ClassDoc
,MemberDoc
,String
andboolean
as parameters, and which returns aString
. Note that only reference parameters are separated with a semicolon, since the semicolon is part of their character representation.So, to sum up:
There are five parameters (int, ClassDoc, MemberDoc, String, boolean) and one return type (String).
这些是本机类型的映射类型。您可以在此处找到概述。
至于你的下一个问题:
因为您没有运行您认为正在运行的代码。 实际上正在运行的代码正在尝试准确调用错误消息中描述的方法,实际上有五个参数(
I
应该单独计算)和一个String < /code>返回类型,但此方法不存在于运行时类路径中(虽然它在编译时类路径中可用),因此出现此错误。另请参阅
NoSuchMethodError
javadoc< /a>:因此,请验证您是否确实运行了您在问题中发布的正确版本的代码,并且在运行时类路径中使用了正确的依赖项,并且在类路径中没有重复的不同版本库。
更新:异常表示实际代码正在(隐式)尝试使用该方法,如下所示:
因为它期待
String
结果当它被声明为void
时。Those are mapping types for native types. You can find an overview here.
As to your next question:
Because you're not running the code you think you're running. The actually running code is trying to call exactly that method described in the error message, with actually five parameters (the
I
should be counted separately) and aString
return type, but this method doesn't exist in the runtime classpath (while it was available in the compiletime classpath), hence this error. Also see theNoSuchMethodError
javadoc:So, verify if you're actually running the right version of the code as you've posted in your question and are using the right dependencies in the runtime classpath and not having duplicate different versioned libraries in the classpath.
Update: the exception signifies that the actual code is (implicitly) trying to use the method like as follows:
Because it is expecting a
String
outcome while it is declaredvoid
.