【发布时间】:2016-03-22 07:42:23
【问题描述】:
在我的一个课程中,我在下面的代码行中调用了 BLH 类的 preOTPOOperations
Class<?> clazz = Class.forName("com.test.BLH");
Object obj = clazz.newInstance();
Class<?>[] paramTypes = new Class[4];
paramTypes[0]=String.class;
paramTypes[1]=String.class;
paramTypes[2]=Integer.class;
paramTypes[3]=COConfig.class;
Method m = clazz.getDeclaredMethod("preOTPOperations", paramTypes);
String responseMessage = (String) m.invoke(obj, new Object[]{cardnumber, null, bankId, myConfig});
但是,当我尝试使用invoke() 调用上述BLH 的preOTPOperations 方法时,我得到了java.lang.NoSuchMethodException。
在 BLH 课程中,我有如下 preOTPOOperations。
public String preOTPOperations(String cardnumber, String mobileNumber, int bankid, COConfig coConfig){
//some code goes here
}
不知道为什么我得到 NoSuchMethodException 尽管在具有公共访问说明符的 BLH 类中有 preOTPOperations。有人好心地提出解决方案。我错过了什么吗?提前致谢!
【问题讨论】:
标签: java reflection nosuchmethoderror