Understanding method signature in NoSuchMethod exception
Asked Answered
C

4

16

I got this exception but resolved it.

java.lang.NoSuchMethodError: antlr.NoViableAltForCharException.<init>
(CLjava/lang/String;II)V

But i'd like to know how to interpret these kind of messages: "(CLjava/lang/String;II)V" Also, does this "init" mention the constructor of NoViableAltForCharException class??

Thanks.

Cottar answered 1/12, 2011 at 15:12 Comment(0)
N
31

Type Signatures - taken from this page.

The JNI uses the Java VM’s representation of type signatures. Table 3-2 shows these type signatures.

Z                               boolean
B                               byte
C                               char
S                               short
I                               int
J                               long
F                               float
D                               double
L fully-qualified-class ;       fully-qualified-class
[ type                          type[]
( arg-types ) ret-type          method type

For example, the Java method:

long f (int n, String s, int[] arr);

has the following type signature:

(ILjava/lang/String;[I)J
Niemeyer answered 1/12, 2011 at 15:21 Comment(0)
B
8

Its looking for a constructor antlr.NoViableAltForCharException(char, String, int, int) but fails to find it in the class.

The <init> method is the constructor and the <cinit> method is the static initialisation block. The parameter types are listed by @gkamal with the addition that V is void. Notionally constructors return void which is the reason for the V at the end of the signature.

BTW: It is perhaps ironic that J is for long and L is for class, when it could have been L for long and J for Java class. ;)

Blumenthal answered 1/12, 2011 at 15:15 Comment(2)
I believe the poster is looking for how to interpret it, and not the actual interpretation.Karmenkarna
Thanks Peter, you answer was helpful in both method signature and init method.Cottar
P
2

See the types docs. It's a convenient shorthand notation.

Ping answered 1/12, 2011 at 15:16 Comment(0)
D
0

You could have an outdated .jar file on the server vs what you're compiling your code with. Double check that all .jar files on the server are same as the ones you're compiling with.

Disinfest answered 12/9, 2017 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.