?
Solved

How to use java.Object.invokeMethod() ?

Posted on 2005-04-19
11
Medium Priority
?
264 Views
Last Modified: 2010-03-31
I'm keep on getting the following error mesage
cannot reslove symbol
symbol : method invokeMethod (java.lang.String,java.lang.Ojbect[])
location: class java.lang.Ojbect
e_MLC.invokeMethod("setTName", 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("setTName", args);

How am I supposed to use invokeMethod() method?
And what am I supposed to do when there's no arguments to pass?
0
Comment
Question by:nagunpyo
  • 6
  • 2
  • 2
  • +1
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13814781
You need to get Method object and invoke them
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1200 total points
ID: 13814790
0
 

Author Comment

by:nagunpyo
ID: 13814849
what's wrong with invokeMethod()?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:CEHJ
ID: 13814876
invokeMethod is non-existent AFAIK
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13814932
>>  what's wrong with invokeMethod()?

it's part of .NET, not Java

;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13814988
>>And what am I supposed to do when there's no arguments to pass?

Pass null
0
 
LVL 2

Assisted Solution

by:limaideal
limaideal earned 800 total points
ID: 13816512
here's code:

Class cls = Class.forName(s_MLC_tName.substring(2));
Object[] args = new Object[1];
Class[] argTypes = new Class[1];
args[0] = s_MLC_tName;
argTypes[0] = s_MLC_tName.getClass(); //set type of argument
e_MLC = cls.newInstance();
//e_MLC.invokeMethod("setTName", args);
Method mthd = cls.getMethod( "setName", argTypes); //find method based-on name and argument
mthd.invoke( c_MLC, args );//invoke method here
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13816924
>>>>
 >>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.newInstance(), new Object[]{ null } );//invoke method here
0
 
LVL 2

Expert Comment

by:limaideal
ID: 13817248
if you want to call something like doMyJob(), you need to:

      mthd.invoke(cls.newInstance(), 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.
0
 

Author Comment

by:nagunpyo
ID: 13820295
Thank you guys! :-D
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13822199
:-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question