Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

InvocationTargetException

 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've used Reflection successfully in a class I'm developing with FORTE .
i.e
Class[] paramTypes = (Class []) Array.newInstance(Class.forName("java.lang.Class"),2 );
but this has suddenly started throwing InvocationTargetExceptions on Execution
Also , on a subsequent line where I invoke a method using reflection , I get the same problem
Method m = AvailableFlightsTableModel.class.getDeclaredMethod("getAvailableFlights",parameterTypes);
 
parthiban subramaniam
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thomas,
Please check and make sure that in the class you are trying to load and the class it uses have all the static members initialised properly and there is no exception been thrown in doing so.
add a try catch block which catches a Throwable .. this will help you a lot ..
This is all I can think of to cause this problem .. if its anything other am happy to learn
Hope this helps..
Have fun

cheers,
parthi.
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've found the answer on the JDC Online Support Forum.
Basically an underlying method called from the method invoked using reflection threw a runtime Exception - NegativeArraySizeException
What threw me was that statements using Reflection prior to the invocation were throwing the InvocationTargetException. I thought that FORTE had gone bananas on me.I haven't fully grasped the power of Reflection
The following reply on the JDC forum proved useful

Re: java.lang.reflect.InvocationTargetException
Author: rvflannery
In Reply To: java.lang.reflect.InvocationTargetException Mar 7, 2002 1:16 PM
Reply 2 of 2


InvocationTargetException is basically a wrapper class for when some method, invoked via Reflection, throws a Runtime Exception. Basically, it means that your target method encountered an Exception- you can get the target exception from getTargetException() . Then, do a stacktrace on that Exception- you should be able to figure out the problem:
catch(InvocationTargetException inv) { inv.getTargetException().printStackTrace();}
P.S I think this site is great and have come across very useful information and sets some very high standards
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parthi,
Your reply is in the same vein as the solution I found earlier.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic