How to load a class function outside declaring class in Java Reflections -


i using java reflections api load functions dynamically variable.when calling functions in same class,the function calls working.

now trying call functions outside declaring class.this code using.

   package com.test.controller;    try    {      class cls = class.forname("com.test.actions");      system.out.println("trying method name");      java.lang.reflect.method method=cls.getmethod(action,string.class,httpservletrequest.class);      system.out.println("got method name"+method);      val=method.invoke(this, instinputtext,request).tostring();     }     catch(exception e){e.printstacktrace();} 

i trying acess different class , functions , following error.

java.lang.illegalargumentexception: object not instance of declaring class 

the exception because of line val=method.invoke(this, instinputtext,request).tostring();.

you passing this instance call, means perform this.method(). instead need create instance of class actions , use in place of this.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -