RE : Java.lang.NoSuchMethodException
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 :
ActionHelper class:
public ActionHelper(BaseAction tbAction) {
iAction = tbAction;
}
GetAuthorisedUnauthorisedRecordsAction is the subclass of the
BaseAction.
with new :
GetAuthorisedUnauthorisedRecordsAction gauUnau = new
GetAuthorisedUnauthorisedRecordsAction();
ActionHelper actionHelper = new ActionHelper( gauUnau );
it is creating the ActionHelper object.
using reflection package iam creating the ActionHelper object.
Class[] tParameterClasses = new Class[1];
tParameterClasses[0] = gauUnau.getClass();
Class tClass = Class.forName( ActionHelper );
Constructor tConstructor =
tClass.getConstructor(tParameterClasses);
Object[] tParameterObjects = new Object[1];
tParameterObjects[0] = (Object) gauUnau;
ActionHelper actionHelper = (ActionHelper)
tConstructor..newInstance(tParameterObjects);
in the above line it is showing exception at
Constructor tConstructor = tClass.getConstructor(tParameterClasses);
exception is java.lang.NoSuchMethodException..
As iam feeling that it does not accept the SubClass object.
it is accepting if i replace the ActionHelper code with below one.
public ActionHelper(GetAuthorisedUnauthorisedRecordsAction tbAction) {
iAction = tbAction;
}
1. Is there any difference b/w "new" and reflection package creation
object.
2. why this is happing.