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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -