解释 java.lang.NoSuchMethodError 消息

发布于 2024-09-03 14:36:00 字数 1430 浏览 8 评论 0原文

我收到以下运行时错误消息(以及堆栈跟踪的第一行,它指向第 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 技术交流群。

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

发布评论

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

评论(2

瑾兮 2024-09-10 14:36:00

来自第 4.3.2 节:

Character     Type          Interpretation
------------------------------------------
B             byte          signed byte
C             char          Unicode character
D             double        double-precision floating-point value
F             float         single-precision floating-point value
I             int           integer
J             long          long integer
L<classname>; reference     an instance of class 
S             short         signed short
Z             boolean       true or false
[             reference     one array dimension

来自 第 4.3.3 节,方法描述符

方法描述符表示该方法采用的参数及其返回的值:

MethodDescriptor:
        ( ParameterDescriptor* ) ReturnDescriptor

因此,

(ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;Ljava/lang/String;Z)
Ljava/lang/String;

转换为:

具有 intClassDocMemberDocString 的方法> 和 boolean 作为参数,并返回一个 String。请注意,只有引用参数才用分号分隔,因为分号是其字符表示的一部分。


所以,总结一下:

为什么括号里有四种类型(ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;Ljava/lang/String;Z),括号后面有一种Ljava/lang/String;当方法 printDocLinkForMenu 明显有五个参数时?

有五个参数(int、ClassDoc、MemberDoc、String、boolean)和一种返回类型(String)。

From section 4.3.2 of the JVM Spec:

Character     Type          Interpretation
------------------------------------------
B             byte          signed byte
C             char          Unicode character
D             double        double-precision floating-point value
F             float         single-precision floating-point value
I             int           integer
J             long          long integer
L<classname>; reference     an instance of class 
S             short         signed short
Z             boolean       true or false
[             reference     one array dimension

From section 4.3.3, Method descriptors:

A method descriptor represents the parameters that the method takes and the value that it returns:

MethodDescriptor:
        ( ParameterDescriptor* ) ReturnDescriptor

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 and boolean as parameters, and which returns a String. Note that only reference parameters are separated with a semicolon, since the semicolon is part of their character representation.


So, to sum up:

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?

There are five parameters (int, ClassDoc, MemberDoc, String, boolean) and one return type (String).

孤君无依 2024-09-10 14:36:00

“ILcom”或“Z”是什么意思?

这些是本机类型的映射类型。您可以在此处找到概述。

Native Type    | Java Language Type | Description      | Type signature
---------------+--------------------+------------------+----------------
unsigned char  | jboolean           | unsigned 8 bits  | Z
signed char    | jbyte              | signed 8 bits    | B
unsigned short | jchar              | unsigned 16 bits | C
short          | jshort             | signed 16 bits   | S
long           | jint               | signed 32 bits   | I
long long      | jlong              | signed 64 bits   | J
__int64        |                    |                  |
float          | jfloat             | 32 bits          | F
double         | jdouble            | 64 bits          | D

此外,签名“L full-qualified-class ;” 表示由该名称唯一指定的类;例如,签名“Ljava/lang/String;”指的是类java.lang.String。此外,在签名前添加 [ 可以使数组成为该类型;例如,[I 表示 int 数组类型。


至于你的下一个问题:

为什么括号里有四种类型(ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;Ljava/lang/String;Z),括号后面有一种Ljava/lang/String;当 printDocLinkForMenu 方法明显有五个参数时?

因为您没有运行您认为正在运行的代码。 实际上正在运行的代码正在尝试准确调用错误消息中描述的方法,实际上有五个参数(I应该单独计算)和一个String < /code>返回类型,但此方法不存在于运行时类路径中(虽然它在编译时类路径中可用),因此出现此错误。另请参阅 NoSuchMethodError javadoc< /a>:

如果应用程序尝试调用类(静态或实例)的指定方法,并且该类不再具有该方法的定义,则抛出此异常。

通常情况下,这个错误会被编译器捕获;仅当类的定义发生不兼容的更改时,此错误才会在运行时发生。

因此,请验证您是否确实运行了您在问题中发布的正确版本的代码,并且在运行时类路径中使用了正确的依赖项,并且在类路径中没有重复的不同版本库。

更新:异常表示实际代码正在(隐式)尝试使用该方法,如下所示:

String s = printDocLinkForMenu(context, cd, (MemberDoc) emd, name, false);

因为它期待 String 结果当它被声明为void时。

What does "ILcom" or "Z" mean?

Those are mapping types for native types. You can find an overview here.

Native Type    | Java Language Type | Description      | Type signature
---------------+--------------------+------------------+----------------
unsigned char  | jboolean           | unsigned 8 bits  | Z
signed char    | jbyte              | signed 8 bits    | B
unsigned short | jchar              | unsigned 16 bits | C
short          | jshort             | signed 16 bits   | S
long           | jint               | signed 32 bits   | I
long long      | jlong              | signed 64 bits   | J
__int64        |                    |                  |
float          | jfloat             | 32 bits          | F
double         | jdouble            | 64 bits          | D

In addition, the signature "L fully-qualified-class ;" would mean the class uniquely specified by that name; e.g., the signature "Ljava/lang/String;" refers to the class java.lang.String. Also, prefixing [ to the signature makes the array of that type; for example, [I means the int array type.


As to your next question:

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?

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 a Stringreturn type, but this method doesn't exist in the runtime classpath (while it was available in the compiletime classpath), hence this error. Also see the NoSuchMethodError javadoc:

Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.

Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.

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:

String s = printDocLinkForMenu(context, cd, (MemberDoc) emd, name, false);

Because it is expecting a String outcome while it is declared void.

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