Lucy20180417
2012-08-15 14:01
浏览 3.7k
已采纳

java.lang.NoSuchMethodError找不到方法,但是那个方法明明存在

错误信息如下:
[code="java"]ERROR 2012-08-15 11:35:12,734 [com.opensymphony.webwork.dispatcher.ServletDispatcher] - Could not execute action
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:300)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:166)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.yzwb.cctv.logic.SignonInterceptor.intercept(SignonInterceptor.java:327)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:272)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:237)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:594)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:490)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:805)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:696)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NoSuchMethodError: com/yzwb/cctv/domain/CivilContract.getContractAmount()D
at com.yzwb.cctv.web.contract.archive.ArchiveContractQueryAction.queryCivilContract(ArchiveContractQueryAction.java:173)
at com.yzwb.cctv.web.contract.archive.ArchiveContractQueryAction.doQuery(ArchiveContractQueryAction.java:78)
... 48 more[/code]
我想问一下下面这个Caused by: java.lang.NoSuchMethodError:******D这句话中最后的D是什么意思,以及这个错误为什么会发生。下面贴错误提示中涉及到的代码
1.JavaBean中的代码,证明那个方法时存在的
[code="java"] private long contractAmount; // 合同金额
public long getContractAmount() {
return contractAmount;
}

public void setContractAmount(Long contractAmount) {
    if(contractAmount != null)
        this.contractAmount = contractAmount;
    else
        this.contractAmount = 0;
}

[/code]
2.调用这个方法并报错的那几行代码
[code="java"] double count = 0;
for(Object o : paginationSupport.getItems()){
CivilContract con = (CivilContract)o;
if(con.getContractAmount() != 0){//报错的位置在这行
count += con.getContractAmount();
}
}
[/code]
谢谢各位!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • Dead_Knight 2012-08-15 14:33
    已采纳

    有时候出现这种怪异的问题,是由于多个版本的class存在。
    比如说:某个java编译成class后,放到classes下面,然后lib目录下,也有这个class所在的jar包,这样就导致classpath实际上有两个相同的class

    打赏 评论
  • tiantianshagn 2012-08-15 14:12

    是否为未编译成功的缘故?

    打赏 评论
  • oyj7454103 2012-08-15 15:03

    检查下 你的配置这个方法的路径!8成是配错了

    打赏 评论
  • wuqq_1999 2012-08-15 16:51

    估计在不同的 jar中存在同样的class
    调用class.getProtectionDomain() 看看class在那个jar中
    删除即可

    打赏 评论

相关推荐 更多相似问题