title: Java Reflection API: getMethod() works fine, invoke fails
body: <p>I think I'm misunderstanding something about Java reflection at a pretty deep level. I've logged what my method is (including what it should be taking as parameters), as well as what I'm passing in and they match up perfectly. getMethod() is clearly retrieving the correct method, but when I invoke it, it gives me the NoSuchMethodException error.</p>
  
  <p>I am targeting createsession with this invocation.</p>
  
  <pre><code>protected void onHandleIntent(Intent i){
      String methodName = i.getStringExtra("methodName");
      String[] data = i.getStringArrayExtra("data");
  
      Method m = null;
      try{
          MyClass c = new MyClass();
          m = c.getClass().getMethod(methodName, String[].class);
          Log.v("this works", "This is printed, no problem");
          m.invoke(c, data);
          Log.v("this does not", "will not be printed");
      } catch(Exception NoSuchMethodException){
          Log.v("nosuchmethod", methodName + " was not found");
      }
  }
  
  public void createsession(String[] data)
      {
          System.out.println(data[0]);
      }
  </code></pre>
  
  <p>This is what I get when I print out my Method object with a .toString() <em>after</em> it's been assigned via getMethod:</p>
  
  <pre><code>method﹕ public void com.myPackage.myApp.MyClass.createsession(java.lang.String[])
  </code></pre>
  
  <p>This makes me think that getMethod isn't the problem area, since that's returning all the correct information...</p>
  
  <p><em>EDIT</em>
  This was working the whole time...</p>
  
  <p>The problem was that that try block became now responsible for all the exceptions that it, or any of the functions I invoke() produce. To this degree, when the function that was invoked, itself returned an exception, the invoke method interpreted it as the only failure it truly knows about: "NoSuchMethodException". My seeing the NoSuchMethodExceptions was simply a NullPointerException inside the invoked method getting into the wrong catch block.</p>
  
  <p>I think I'll leave this question up and unanswered forever, as a fair warning of hours spent. I feel like this could be a useful piece of knowledge for someone else.</p>