[nmglug] Java invoke question

Jason Davis mohadib at openactive.org
Fri Feb 3 08:21:30 PST 2006


Aaron,

Also , if you know what classes you need to use before compile time you
can make things easier.

NewThingWithMain  ntwn = NewThingWithMain.main(new String[]{"arg1" ,
"arg2"});

If you don't know whats going to be loaded , like in the case of
plugins , then reflection is the thing to use.

hth,
jd

On Fri, 2006-02-03 at 08:26 -0700, Aaron Birenboim wrote:
> I'm trying to write a Java app that launches other apps.   I can't seem
> to get parameters into the
> main method through Method.Invoke.
> 
> Here's the code:
> 
>     Class cl = Class.forName(classNam);
>     Method mMain = cl.getMethod("main",String[].class);
>     //mMain.invoke(cl,argv);
>     //mMain.invoke(cl,(java.lang.Object[])argv);
>     mMain.invoke(null,(java.lang.Object[])argv);  // javaServer.java:184
> 
> It throws IllegalArgumentException: wrong number of arguments
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:585)
>         at ClassRunner.runCmd(javaServer.java:184)
> 
> I've seen similar example code...  but mine does not work.
> Why am I seeing NativeMethod stuff?  This is supposed to be all Java.
> Any ideas where to get help?
> 
>                     aaron
> 
> 
> 
> _______________________________________________
> nmglug mailing list
> nmglug at nmglug.org
> http://www.nmglug.org/mailman/listinfo/nmglug





More information about the nmglug mailing list