[nmglug] Java invoke question

Aaron Birenboim eunichs at boim.com
Fri Feb 3 07:26:06 PST 2006


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






More information about the nmglug mailing list