gpt4 book ai didi

java - 导致 java.lang.NoSuchMethodException 的 getDeclaredMethod

转载 作者:行者123 更新时间:2023-11-30 10:47:35 24 4
gpt4 key购买 nike

在我的一个类(class)中,我在下面的代码行中调用了 BLH 类的 preOTPOperations

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 类中,我有如下的 preOTPO 操作。

public String preOTPOperations(String cardnumber, String mobileNumber, int bankid, COConfig coConfig){

//some code goes here

}

尽管在 BLH 类中有带有公共(public)访问说明符的 preOTPOperations,但我不确定为什么我会收到 NoSuchMethodException。有人好心地提出了解决方案。我错过了什么吗?提前致谢!

最佳答案

您需要将Integer.class 更改为int.classIntegerint 不是同一类型,并且找不到方法,因为您指定了错误的类型。

关于java - 导致 java.lang.NoSuchMethodException 的 getDeclaredMethod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36148668/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com