我看过一些关于 getDeclaredMethod 的 NoSuchMethodException 的帖子,但我仍然无法摆脱这个问题。
我将问题简单化了,有人可以解决这个问题吗:
public class MainMethodTest {
public static void main(String[] args) {
try {
//Method m = MainMethodTest.class.getDeclaredMethod("main");
Method m = MainMethodTest.class.getDeclaredMethod("main", MainMethodTest.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
}
最佳答案
Method m = MainMethodTest.class.getDeclaredMethod("main", MainMethodTest.class);
正在尝试查找代码中没有的 main(MainMethodTest argument)
方法。
如果你想获得main(String[] argument)
方法使用
Method m = MainMethodTest.class.getDeclaredMethod("main", String[].class);
关于java - getDeclaredMethod 不断给出 NoSuchMethodException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31229589/