title: Not able to invoke main method using Reflection - IllegalArgumentException: argument type mismatch
body: <p>I am writing a sample application for learning reflection. I am trying to invoke the main method define in one class from another class using reflection but i am getting </p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch</p>
  </blockquote>
  
  <p>Find below the code I am trying to execute.</p>
  
  <p>Class from which main method is invoked</p>
  
  <pre><code>import java.lang.reflect.Method;
  public class Invoker {
  
  
  public static void main(String[] args) throws Exception {
      Class clazz = Class.forName("com.nagpal.invokemainmethod.Invoked");
  
      Method method = clazz.getMethod("main", new Class[] { String[].class });
  
      Object[] params = new Object[4];
  
      params[0] = "arg 1";
      params[1] = "arg 2";
      params[2] = "arg 3";
      params[3] = "arg 4";
  
      method.invoke(null, new Object[] { params });
  }
  </code></pre>
  
  <p>Class whose main method is to be invoked</p>
  
  <pre><code>public class Invoked {
  
  
  public static void main(String[] args) {
      if (args.length &lt; 3) {
          throw new IllegalArgumentException();
      }
  
      for (int i = 0; i &lt; args.length; i++) {
          System.out.println("args[" + args[i] + "]");
      }
    }
  
    }
  </code></pre>