java.lang.NoSuchMethodError - com/myApp/Client.cypherCBC(Ljava/lang/String;)Ljava/lang/String;
Asked Answered
J

4

11

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();
}
Junior answered 29/8, 2016 at 5:17 Comment(6)
This sounds like maybe the underlying dependencies have changed (read: the JARs are not the same in both places).Sumptuary
Welcome to Stack Overflow. You can improve your question. Please read Minimal, Complete, and Verifiable example. When your code shows your precise problem with nothing extra, you are showing respect to those who volunteer to help you.Jacquiline
If you format your code to eliminate scrolling, you make it easier for others to help you.Jacquiline
Looks like you need to pass an array of StringsIndeterminacy
Add the code of cypherCBC() and the complete stacktraceKreutzer
DV for misquoting the exception.Faubourg
U
8

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.

Unicellular answered 29/8, 2016 at 6:26 Comment(3)
Due to working in projection (remote machine) am unable to debug and not even see build path. Jars are in src folder and build.xml have jars location as pathelement which is in src folder. But running Client.class.getResource("Client.class") gives me jar:file:/vobs/vob_central/gaia/lib/gas.jar!/com/aldata/gaia/server/impl/service/Client.class Note here am having new gas.jar and location /vobs/vob_central/gaia/lib/gas.jar having older jar. But even though im having my new jar in src folder and it should take this path only.Junior
then the class has been loaded from the jar /vobs/vob_central/gaia/lib/gas.jar . i didnt get you about the "src" folder, is it a folder in the deployed env. i assume that you are suing java default class loader which is URLListClass loader, this loader has list of URLs for all jars which is mentioned in the -classpath. it goes through the urls based on the given order , so this /vobs/vob_central/gaia/lib/gas.jar is on the top op the list and the jar you wanted is in the bottom of the listUnicellular
one more thing, even though your application runs in a remote machine, you can try remote debugging. if firewalls or access rights doesn't allow to do that, try to dump the complete application to your local machineUnicellular
B
3

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

Bandaranaike answered 29/1, 2019 at 8:15 Comment(0)
H
0

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.

Herr answered 13/7, 2022 at 12:11 Comment(0)
K
0

Update the bcprov-jd* Jar to latest from maven repo, it will resolve the issue

Kweiyang answered 4/4 at 8:16 Comment(3)
Can you explain (1) how to do that, (2) why it should solve the problem?Yearbook
Welcome to Stack Overflow! Your answer could be improved with additional supporting information. If possible, please edit your post to add further details, such as explanations or documentation, so that others can confirm that your answer is correct. You can find more information in How do I write a good answer? - "Brevity is acceptable, but fuller explanations are better." It might be helpful to review some highly upvoted answers as examples to follow. Thanks!Carlottacarlovingian
This is an incomplete answer, please provide a descriptive answer to help the asker and othersHinkel

© 2022 - 2024 — McMap. All rights reserved.