About Java.lang.reflect.InvocationTargetException

Source: Internet
Author: User

Today encountered java.lang.reflect.InvocationTargetException error, card for a good while, error code

  

 try   {Class  <?> c= class.f             ORName ("Com.csdhsm.chat.server.handler." + HandlerName); Class  <?>[] arg=new  class[]{socketrequest., Socketresponse. class              };            Method  =c.getmethod (Action,arg); Logger.getlogger (Logger.  class ).            Info ("instanced processor" + HandlerName); Method.invoke (C.newinstance (),  new           Object[]{request,response});  catch   (Exception e) {E.printstack         Trace (); } 

Error locked in Method.invoke (C.newinstance (), New Object[]{request,response}); This sentence, I always thought reflected what was wrong, and then Google later found that the method is a mistake, if you want to see the error inside, need to do

Try{Method Method=Obj.getclass (). GetMethod (MethodName);        Method.invoke (obj); } Catch(nosuchmethodexception e) {Throw NewRequestnotfoundexception ("Method not found:" +MethodName, E); } Catch(InvocationTargetException e) {throwable T=E.getcause ();            T.printstacktrace (); Throw Newobjectfactoryexception (t); } Catch(Exception e) {e.printstacktrace (); Throw Newobjectfactoryexception (e); }
emphasis on throwable t = E.getcause (); This sentence.

Reference link http://www.oschina.net/question/86510_14830

About Java.lang.reflect.InvocationTargetException

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.