Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

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();
}
like image 966
shankar jha Avatar asked Aug 29 '16 05:08

shankar jha


People also ask

What is Ljava Lang string?

Ljava.lang.String stands for the string class (L followed by class/interface name) Few Examples: Class. forName("[D") -> Array of primitive double. Class.

What does NoSuchMethodError mean?

NoSuchMethodError is a runtime error in Java which occurs when a method is called that exists at compile-time, but does not exist at runtime. The Java Garbage Collector (GC) cannot free up the space required for a new object, which causes a java. lang.


2 Answers

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

like image 56
shamika Avatar answered Oct 22 '22 01:10

shamika


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.

like image 20
hunter Avatar answered Oct 22 '22 01:10

hunter