mardi 22 mars 2016

getDeclaredMethod leading to java.lang.NoSuchMethodException

In one of my classes i have put below lines of code to call the preOTPOperations of BLH class

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});

But, i get java.lang.NoSuchMethodException, when i try to invoke preOTPOperations method of BLH as above using invoke().

In BLH class i have preOTPOperations as below.

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

    //some code goes here

}

Not sure why i am getting NoSuchMethodException in spite of having preOTPOperations in BLH class with public access specifier. Someone kindly suggest the solution. Am i missing something? Thanks in advance!





Aucun commentaire:

Enregistrer un commentaire