title: Java Reflection - Object is not an instance of declaring class
body: <p>This question is being asked everywhere on Google but I'm still having trouble with it.  Here is what I'm trying to do.  So like my title states, I'm getting an 'object is not an instance of declaring class' error.  Any ideas?  Thanks!</p>
  
  <p>Main.java</p>
  
  <pre><code>Class&lt;?&gt; base = Class.forName("server.functions.TestFunction");
  Method serverMethod = base.getMethod("execute", HashMap.class);
  serverMethod.invoke(base, new HashMap&lt;String, String&gt;());
  </code></pre>
  
  <p>TestFunction.java</p>
  
  <pre><code>package server.functions;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import server.*;
  
  public class TestFunction extends ServerBase {
  
      public String execute(HashMap&lt;String, String&gt; params)
      {
          return "Test function successfully called";
      }
  }
  </code></pre>