I am working on a Java EE application, which runs on a WAS application server. I am also using Hibernate. JRE version 7
Here is the error I am getting:
[12/1/14 9:04:37:199 SAST] 00000155 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0014E: Uncaught service() exception root cause /operations/enrollstudents.jsp: com.ibm.websphere.servlet.error.ServletErrorReport: java.lang.NoSuchMethodError: com/ictworx/json/JsonHelper.getJson(Ljava/util/List;[Ljava/lang/String;)Ljava/lang/String;
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:695)
at com.ibm._jsp._enrollstudents._jspService(_enrollstudents.java:187)
In the last line of code above, what do the underscores mean? Where do they come from. If I click on _enrollstudents.java:187, it says "Source not found for com.ibm._jsp._enrollstudents" Which kinda makes sense since my enrollstudents.jsp page is not in the com.ibm package. Why would it think it is there?
So based on what I have found so far it looks like this should have been caused because the arguments I am sending do not match the parameters of the method I am calling. However I triple checked and they do.
I am sending a java.util.List and then 2 strings. And my method's parameters are a Collection, and then a vararg of String. Here is the method in the JsonHelper class:
public static String getJson(Collection<?> objects, String ...fields) {
//actual method implementation here, which has always worked.
}
And here is the relevant code on the page that calls the method:
<%@page import="com.companyname.json.JsonHelper"%>
<%
//irrelevant stuff here
query = sess.createQuery("FROM JobLevel WHERE active = :active ORDER BY lower(jobLevel) ASC");
query.setBoolean("active", true);
List<JobLevel> job_levels = (List<JobLevel>) query.list();
%>
<!DOCTYPE html>
<html>
<head>
<!--irrelevant stuff here-->
<script type="text/javascript">
var job_levels = <%= JsonHelper.getJson(job_levels, "uid", "jobLevel") %>;
var job_functions = <%= JsonHelper.getJson(job_functions, "uid", "jobFunction") %>;
root cause is that you most likely have compiled a class against a different version of the class that is missing a method, than the one you are using when running it.
Look at the stack trace ... If the exception appears when calling a method on an object in a library, you are most likely using separate versions of the library when compiling and running. Make sure you have the right version both places.
If the exception appears when calling a method on objects instantiated by classes you made, then your build process seems to be faulty. Make sure the class files that you are actually running are updated when you compile.
来源:https://stackoverflow.com/questions/27223963/confusing-java-lang-nosuchmethoderror