Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Java.lang.NoSuchMethodException

Thread view: 
ramakrishna - 04 May 2006 07:54 GMT
HI,
  can any one tell me, why NoSuchMethodException will come in
Class.getConstructor( Class[] parameterTypes) method.
 In my program Iam using the one constructor and iam calling the
constructor by passing array of class object

i created the same object using "new" operator with constructor
arguments and its works fine.

my code is :

with new :
GetAuthorisedUnauthorisedRecordsAction gauUnau = new
GetAuthorisedUnauthorisedRecordsAction();

        com.citibank.treasuryintegration.ui.action.ActionHelper actionHelper
= new com.citibank.treasuryintegration.ui.action.ActionHelper( gauUnau
);

its work fine.

using reflection package :
     Class[] tParameterClasses = new Class[1];
     tParameterClasses[0] = gauUnau.getClass();
     Constructor tConstructor =
tClass.getConstructor(tParameterClasses);
in the above line it is showing exception
Bjorn Abelli - 04 May 2006 10:40 GMT
"ramakrishna" wrote...

> can any one tell me, why NoSuchMethodException will come in
> Class.getConstructor( Class[] parameterTypes) method.

Your code snippets are just a tab too short to give a complete answer.

Whn you say that "NoSuchMethodException will come", do you mean as a
compilation error or as a runtime error.

As getConstructor *can* throw a NoSuchMethodException, you need to wrap it
in a try-catch-clause.

If you have done that, and you get it as a runtime error, you need to
provide a bit more code.

> In my program Iam using the one constructor and iam calling the
> constructor by passing array of class object
[quoted text clipped - 7 lines]
> GetAuthorisedUnauthorisedRecordsAction gauUnau = new
> GetAuthorisedUnauthorisedRecordsAction();

Is GetAuthorisedUnauthorisedRecordsAction a subtype of something else?

If the constructor of ActionHelper takes a supertype of
GetAuthorisedUnauthorisedRecordsAction, the constructor itself will work
when used in an ordinary manner...

> com.citibank.treasuryintegration.ui.action.ActionHelper actionHelper
> = new com.citibank.treasuryintegration.ui.action.ActionHelper( gauUnau
> );

...but it will not correspond to the signature of the constructor:

>      Class[] tParameterClasses = new Class[1];
>      tParameterClasses[0] = gauUnau.getClass();
>      Constructor tConstructor =
>         tClass.getConstructor(tParameterClasses);

So, if ActionHelper actually expects a supertype of
GetAuthorisedUnauthorisedRecordsAction, you'll get a NoSuchMethodException,
because GetAuthorisedUnauthorisedRecordsAction is not a parameter in the
constructor's signature.

// Bjorn A


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.