haii
I have a problem while accessing a class(A) through "reflection" from class B....
i want to pass a parameter to class A...
My code is like this...

Method idMethod =  Class.forName(ClassName).getMethod(FunctionName,null);
Method getMethod =  Class.forName(ClassName).getMethod("getInstance", new Class[]{Class.forName("java.lang.String")});


Object object = getMethod.invoke(Class.forName(ClassName()),new Object[]{dboption});


lists = (ArrayList)idMethod.invoke(object,personId);

i will get correct result when the parameter is a String(Like above)...But how can i pass an Object ...

Which method are you wanting to pass an object to? "idMethod" is getting a no-arg method and "getMethod" is getting this method getInstance(String) with this line

Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{Class.forName("java.lang.String")});

. If you need getInstance(Object) the you need to use

Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{java.lang.Object.class});

Your question is not very clear, so if that is not what you were asking you will need to clarify it a bit more.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.