I have imported the fully qualified name of the class and created an instance of the class. I then proceeded to acquire the private method name of the class:
InvokeCallWebservice invokeCallWebservice = new InvokeCallWebservice();
Method method = null;
try {
method = invokeCallWebservice.getClass().getDeclaredMethod("Fully Qualified Class Name.getURL", String.class);
}
catch (SecurityException e) {
System.out.println(e.getCause());
}
catch (NoSuchMethodException e) {
System.out.println(e.getCause());
}
System.out.println(method.getName());
An exception is thrown because method is null. I am not sure the reason which could be the class exists in a different project and package or because I need to specify the second argument as many times as there are parameters in the method. Can I actually invoke this on a private method?
Here is the stack trace:
java.lang.NoSuchMethodException: InvokeCallWebservice.getURL(java.lang.String)
at java.lang.Class.getDeclaredMethod(Class.java:1937)
at com.geico.debug.Debug.main(Debug.java:39)
Fully Qualified Class Name.getURL. No, just the name of the method.Stringparameter?private void getURL(String IPNumber, String ClaimNumber, String EventID, String UserEmail, String logId)getDeclaredMethod("getURL", String.class, String.class, String.class, String.class, String.class);to match its parameter types. I've updated my answer.