Method.invoke throws java.lang.IllegalArgumentException: wrong number of arguments

 

Above Java code is an unit test case, it uses reflection to get the private method downloadFile of class ZhangyoobaoLeshuaMerchantRegister, and set the access level of this method to public, then call it with parameters.

But running this line  result = method.invoke(register, null);  will got following error

 

The method signature of com.jh.paymentchannel.channel.zhangyoobao.ZhangyoobaoLeshuaMerchantRegister#downloadFile

 

To fix this issue, change following line

to