nagunpyo
asked on
How to use java.Object.invokeMethod() ?
I'm keep on getting the following error mesage
cannot reslove symbol
symbol : method invokeMethod (java.lang.String,java.lan g.Ojbect[] )
location: class java.lang.Ojbect
e_MLC.invokeMethod("setTNa me", args);
And here's part of my code that's causing the problem
Object e_MLC;
s_MLC_tName = getTName() + "_MLC";
Class cls = Class.forName(s_MLC_tName. substring( 2));
Object[] args = new Object[1];
args[0] = s_MLC_tName;
e_MLC = cls.newInstance();
e_MLC.invokeMethod("setTNa me", args);
How am I supposed to use invokeMethod() method?
And what am I supposed to do when there's no arguments to pass?
cannot reslove symbol
symbol : method invokeMethod (java.lang.String,java.lan
location: class java.lang.Ojbect
e_MLC.invokeMethod("setTNa
And here's part of my code that's causing the problem
Object e_MLC;
s_MLC_tName = getTName() + "_MLC";
Class cls = Class.forName(s_MLC_tName.
Object[] args = new Object[1];
args[0] = s_MLC_tName;
e_MLC = cls.newInstance();
e_MLC.invokeMethod("setTNa
How am I supposed to use invokeMethod() method?
And what am I supposed to do when there's no arguments to pass?
You need to get Method object and invoke them
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what's wrong with invokeMethod()?
invokeMethod is non-existent AFAIK
>> what's wrong with invokeMethod()?
it's part of .NET, not Java
;-)
it's part of .NET, not Java
;-)
>>And what am I supposed to do when there's no arguments to pass?
Pass null
Pass null
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>>>
>>And what am I supposed to do when there's no arguments to pass?
Pass null
>>>>
This is how:
Class cls = Class.forName(s_MLC_tName. substring( 2));
Class[] argTypes = new Class[] { java.lang.String.class }; // put the correct type of arg in here
Method mthd = cls.getMethod( "setTName", argTypes); //find method based-on name and argument
mthd.invoke(cls.newInstanc e(), new Object[]{ null } );//invoke method here
>>And what am I supposed to do when there's no arguments to pass?
Pass null
>>>>
This is how:
Class cls = Class.forName(s_MLC_tName.
Class[] argTypes = new Class[] { java.lang.String.class }; // put the correct type of arg in here
Method mthd = cls.getMethod( "setTName", argTypes); //find method based-on name and argument
mthd.invoke(cls.newInstanc
if you want to call something like doMyJob(), you need to:
mthd.invoke(cls.newInstanc e(), null);//invoke method here
The following is Doc from Method.invoke:
If the number of formal parameters required by the underlying method is
0, the supplied <code>args</code> array may be of length 0 or null.
mthd.invoke(cls.newInstanc
The following is Doc from Method.invoke:
If the number of formal parameters required by the underlying method is
0, the supplied <code>args</code> array may be of length 0 or null.
ASKER
Thank you guys! :-D
:-)