Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How to execute a method of the class loaded

Hi,

I have to execute the method of com.common.helper.EANCRatingHelper" + version

version may be 1,2, etc

if version = 1 the class is com.common.helper.EANCRatingHelper1;

Iam able to load the class using following code.But iam unable to execute the method of the above class

Can anybody help me how to execute the method of the class loaded.

Following is the code

String version = getHelperClassVersion(requestDate);
String helperClass = "com.redroller.common.carriers.eanc.helper.EANCRatingHelper" + version;

Class eancRatingHelper = Class.forName(helperClass);
eancRatingHelper.newInstance();

eancRatingHelper.saveRating(); This is not executing throwing an error no method.

thanks

Naveen
[831 byte] By [naveenkumarg1] at [2007-11-11 7:19:10]
# 1 Re: How to execute a method of the class loaded
I think you need to cast it to the class like so...

Class eancRatingHelper = Class.forName(helperClass);
eancRatingHelper eancRH = (eancRatingHelper)eancRatingHelper.newInstance();
eancRH.saveRating();

newInstance returns an Object and you were not doing anything with it. Then you tryed to call saveRating as a static method of the class which it probably isn't.

I think this will work, but i haven't tried it so don't get mad if it doesn't.
;)
Joe Beam at 2007-11-11 22:38:43 >