title: Java - java.lang.NoSuchMethodException
body: <p>I try to use this code (<strong>Update</strong> m_set is used inside for loop which goes through few methods which use different  type arguments. If I would add for example int.class in <code>getMethod</code>, I would get error after one iteration, because next method would require String.class. Is it possible to solve such problem using reflection?):</p>
  
  <pre><code>Method m_set = product.getClass().getMethod(method_name);
  m_set.invoke(product, method_value);
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code> Exception in thread "main" java.lang.NoSuchMethodException: test.NormalChair.setHeight()
          at java.lang.Class.getMethod(Class.java:1655)
          at test.ProductTrader.create(ProductTrader.java:68)
          at test.Test.main(Test.java:32)
  </code></pre>
  
  <p>In error it shows that it tries to find method in class that I use this method. But that method is in parent class and it is public method. I know if I would use <code>getDeclaredMethod</code>, it would give similar error, but why it gives this error using <code>getMethod</code>?</p>
  
  <p>My class thas has this method:</p>
  
  <pre><code>public abstract class AbstractChair {
      public String name;
      public int height;
      public AbstractChair() {
      }
  
      public AbstractChair(String name, int height){
          this.name = name;
          this.height = height;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public int getHeight() {
          return height;
      }
  
      public void setHeight(int height) {
          this.height = height;
      }   
  }
  </code></pre>
  
  <p>My class that I try to use this method on:</p>
  
  <pre><code>public class NormalChair extends AbstractChair {
      public NormalChair() {
          super();
      }
  
      public NormalChair(String name, int height) {
          super(name, height);
      }
  
  
      // Copy constructor
      public NormalChair(NormalChair chair) {
        this(chair.getName(), chair.getHeight());
      }
  
  }
  </code></pre>
  
  <p><strong>Update2</strong></p>
  
  <p>If I do something like this:</p>
  
  <pre><code>if(method_name == "setHeight"){
    Method m_set = product.getClass().getMethod(method_name, int.class);
    m_set.invoke(product, method_value);
  }
  else if (method_name == "setName")
  {
    Method m_set = product.getClass().getMethod(method_name, String.class);
    m_set.invoke(product, method_value);
  }
  </code></pre>
  
  <p>Then error disappears. Can someone suggest more universal approach?</p>