Java Reflection getDeclaredMethod(...) Returning Null -


i have imported qualified name of class , created instance of class. proceeded acquire private method name of 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 thrown because method null. not sure reason class exists in different project , package or because need specify second argument many times there parameters in method. can invoke on private method?

here stack trace:

java.lang.nosuchmethodexception: invokecallwebservice.geturl(java.lang.string) @ java.lang.class.getdeclaredmethod(class.java:1937) @ com.geico.debug.debug.main(debug.java:39) 

you have class first, , class, method want get, using method name , parameters.

class clazz = class.forname("package.classiwant");  method mymethod = clazz.getdeclaredmethod("geturl", string.class); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -