Java NoSuchMethodError when Method Exists

一世执手 提交于 2019-12-04 10:47:19

This is a very simple to troubleshoot. you have used that method and you were able to compile that class which uses this method.

so that means at compile time it reefers the class PlayerUtil which has this method.

But runtime class loader has loaded the class PlayerUtil which doesn't contain this method. now what you have to do is just find out where that class has been loaded from (at run time)

if you can recreate the problem while it is running using eclipse/IDEA follow these steps. (if it runs in in application server or standalone application, then start the application server or application with debug enabled.and you can do remote debug from your IDE).

  1. put a break-point where exception was thrown (where you call this method).
  2. start to debug , it will hit the break-point.
  3. then evaluate this expression PlayerUtil.class.getResource("PlayerUtil.class")

4.you can find the path where the class was loaded from.

now you have two options , decompile the class and check whether that method is these (same return type, same name , same args).

or in debug , you can evaluate PlayerUtil.class.getDeclaredMethods() to find out.

So you can solve the problem by rectifying the class path entries if it was loaded from a wrong place.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!