title: Can't invoke a method obtained through reflection
body: <p>I am getting the error</p>
  <pre><code>Cannot invoke &quot;Object.getClass()&quot; because &quot;obj&quot; is null
  </code></pre>
  <p>on the line</p>
  <pre><code>            m.invoke(null);
  </code></pre>
  <p>Here are the classes:</p>
  <pre><code>package device;
  
  public class Conveyor {
      private String ID;
      
      public Conveyor(String ID) {this.ID = ID;}
      
      public void Start() {
          
      }
  
      public void Stop() {
          
      }
  
  }
  
  
  package main;
  
  import java.lang.reflect.Method;
  
  import device.Conveyor;
  
  public class Main {
      
      public static void main(String args[]) {
          
          Conveyor myConveyor = new Conveyor(&quot;C1&quot;);
  
          Class&lt;Conveyor&gt; conveyorClass = (Class&lt;Conveyor&gt;) myConveyor.getClass();
  
          for (Method m : conveyorClass.getMethods()) {
              System.out.println(m.getName());
              if (m.getName().equals(&quot;Start&quot;)) {
                  try {
                      m.invoke(null);
                  } catch (Exception ex) {
                      System.err.println(ex.getLocalizedMessage());
                  }
              }           
          }
      }
  }
  </code></pre>