jeudi 27 août 2015

illegalargumentexception argument type mismatch while invoking a method via reflection in RCP project

I am trying to invoke a method of class via reflection in RCP project,the Class is in a reference jar,while invoking the method illegalArgumentException argument type mismatch is thrown,the method which is invoked contains two arguments one of userdefined type and another of string,the class gets loaded and i also get the method but when i invoke the method with the arguments expection is thrown,but when i run this with a simple java application it works fine, is there any another way to do it in RCP ? I'm new to RCP.

loading jar :

       File file = new File("C:\\Users\\sample.jar"); 
       URL jarfile;
       jarfile = new URL("jar", "","file:" + file.getAbsolutePath()+"!/");    
       this.loader = URLClassLoader.newInstance(new URL[] {jarfile});

     invoking method: 
        c = this.loader.loadClass("com.Sample");
          Method[] methods = c.getMethods();
          for (Method method2 : methods) {
            if((method2.getName().equals(methodName))){
              method2.setAccessible(true);
              Object[] param={new myType(),new String("Sample")};
              method2.invoke(c.newInstance(),param);
            } 





Aucun commentaire:

Enregistrer un commentaire