problem with reflection

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jan 2008
Posts: 71
Reputation: ajithraj is an unknown quantity at this point 
Solved Threads: 1
ajithraj ajithraj is offline Offline
Junior Poster in Training

problem with reflection

 
0
  #1
Apr 10th, 2008
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 ...
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,505
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: problem with reflection

 
0
  #2
Apr 10th, 2008
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
  1. Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{Class.forName("java.lang.String")});
. If you need getInstance(Object) the you need to use
  1. 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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC