简体   繁体   中英

java.lang.NoSuchMethodError - Ljava/lang/String;)Ljava/lang/String;

My code is giving an error below;

Exception in thread "main" java.lang.NoSuchMethodError: com/myApp/Client.cypherCBC(Ljava/lang/String;)Ljava/lang/String;

But it's working fine in an another local environment. My code so far is below;

try {
    System.out.println("Encrypted CBC passwd : "
         + Client.cypherCBC("CypherThePassword"));
} catch (Exception e) {
    e.printStackTrace();
}

This is due to a run-time JAR or class mismatch. the "Client" class which was there at the time you compile your application has a static method "cypherCBC" which gets String parameter, but at run-time class loader has loaded the "Client" class which doesn't have that kind of method (same name with same signature).

if you can debug the application at runtime, put a break-point at the line which exception was thrown, then try to evaluate following expression,

Client.class.getResource("Client.class")

, then you can find where the class has been leaded from, then you can decompile and try to troubleshoot the issue.

I got the same error while running a web application in Weblogic. The reason for this error is there are two versions of classes are in the environment.To fix this you have to figure out which .class is using at the run time. I used following to identify which class is loaded at run time.

-verbose:class

There is a duplicate class on your classpath. So, That is why JVM is getting confused that which one needs to pick because both classes have a same method with a different signature that you are trying to call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM