title: Using reflection to call static method for return value
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4770425/how-do-i-invoke-a-private-static-method-using-reflection-java">How do I invoke a private static method using reflection (Java)?</a>  </p>
  </blockquote>
  
  
  
  <p>So there is a method named something along the lines of "getInstance" which just returns an instance of a certain class. It's a static method with no arguments. </p>
  
  <p>How could I call that method, and get the return value (the instance) of the class? Every method I try to use requires me to have an instance of the class in the arguments it seems.</p>
  
  <p>For example, I try to use </p>
  
  <pre><code>Method method = classLoader.loadClass("testClass").getMethod("getInstance", null);
              Object object = method.invoke(null, null);
  </code></pre>
  
  <p>but I always get a null pointer exception at this line,</p>
  
  <pre><code>Object object = method.invoke(null, null);
  </code></pre>
  
  <p>Which I'm assuming I get since the object it asks for is null.</p>
  
  <p>Thanks for any help.</p>
  
  <p>Edit: Method is not null. I am doing a <code>System.out.println(method == null);</code> and it prints out false.</p>