title: Java reflection multiple parameters
body: <p>I am trying to use Java reflection and I have two different methods to call. One of them has a single String parameter and second one has two String parameters. I've managed to get first one working, but still struggling with the second one. I've checked references to two other questions (<a href="https://stackoverflow.com/questions/5454249/java-reflection-getmethodstring-method-object-class-not-working">Java reflection: getMethod(String method, Object[].class) not working</a> and <a href="https://stackoverflow.com/questions/8843953/how-to-invoke-method-with-variable-arguments-in-java-using-reflection">How to invoke method with variable arguments in java using reflection?</a>), but unfortunately had no luck with them. I keep getting the following exception:</p>
  
  <pre><code>java.lang.NoSuchMethodException: controllers.InventoryController.combineItems([Ljava.lang.String;)
  at java.lang.Class.getMethod(Unknown Source)
  </code></pre>
  
  <p>Here is my working part of code:</p>
  
  <pre><code>Class[] paramString = new Class[1];
  paramString[0] = String.class;
  try {
      Class cls = this.getClass();
  
      Method method = cls.getDeclaredMethod(commandParts[0], paramString);
      method.invoke(this, new String(commandParts[1]));
  } catch (Exception ex) {
      System.out.println("Doesn't work");
      ex.printStackTrace();
  }
  </code></pre>
  
  <p>Now here is the part I can't get to work:</p>
  
  <pre><code>Class[] paramString = new Class[2];
  paramString[0] = String[].class;
  
  try {
      Class cls = this.getClass();
  
      Method method = cls.getMethod(commandParts[0], paramString[0]);
      method.invoke(this, new String[]{commandParts[1], commandParts[2]});
  } catch (Exception ex) {
      System.out.println("Doesn't work");
      ex.printStackTrace();
  }
  </code></pre>
  
  <p>What is the correct way of passing multiple parameters?</p>