[nmglug] Java invoke question

Jason Davis mohadib at openactive.org
Fri Feb 3 07:35:25 PST 2006


maybe this will help you.
cheers,
jd


  private void loadPlugins(final List <PluginInfo> plugInfos){
    for(PluginInfo info : plugInfos){
      try{
        
        Class plug = Class.forName(info.getPluginClassName());
        
        Map <String , String> args = info.getArgs();
        
        SwingBotPlugin plugin = (SwingBotPlugin)plug.getConstructor
        (new Class[] { SwingBot.class , Map.class }).newInstance(this ,
args);
        
        for(String word : plugin.getReservedWords()){
          reservedWords.add(word);
        }
        
        eventHandler.registerPlugin(plugin);
        
        System.out.println("  Loaded " + info.getPluginClassName());
      }
      catch (ClassNotFoundException e) {
        e.printStackTrace();
        System.err.println("Can't find pugin " +
info.getPluginClassName() );
      }catch (NoSuchMethodError e) {
        e.printStackTrace();
        System.err.println("Found bad plugin " +
info.getPluginClassName());
      }catch (Exception e) {
        e.printStackTrace();
        System.err.println("Could not load plugin " +
info.getPluginClassName());
      }
    }
      
  }

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