title: java.lang.NoSuchMethodException Java
body: <p>I'm trying to call 2 different versions of the same dependency library (<code>jars</code>) within a top level <code>Main class</code>. So I created an interface with 2 implementation classes, both classes have a run method which makes use of common apis one will use <code>somejar-1.0.0-SNAPSHOT.jar</code> and the other will use <code>somejar-2.0.0-SNAPSHOT.jar</code> by explicitly calling ClassLoader. </p>
  
  <pre><code>public static void main(String[] args) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
  
      ClassLoader loader1 = new URLClassLoader( new URL[] { new File("/Users/haddad/.m2/repository/com/company/somejar-1.0.0-SNAPSHOT.jar").toURL() });
      ClassLoader loader2 = new URLClassLoader( new URL[] { new File("/Users/haddad/.m2/repository/com/company/somejar-2.0.0-SNAPSHOT.jar").toURL() });
  
      Class&lt;?&gt; c1 = loader1.loadClass("com.engine.na.EngineV1");
      Class&lt;?&gt; c2 = loader2.loadClass("com.engine.na.EngineV2");
  
      IEngine app1 = (IEngine) c1.newInstance();
      IEngine app2 = (IEngine) c2.newInstance();
  
      Integer s1 = app1.run();
      Integer s2 = app2.run();
      Assert.equals(s1,s2,"Outputs from somejar-1.0 and somejar-2.0 did not match, perhaps somejar-2.0 has regressed?");
  }
  </code></pre>
  
  <p>Here are EngineV1 and V2 with Interface:</p>
  
  <pre><code>public Interface IEngine {
      Integer run();
  }
  
  public class EngineV1 implements IEngine {
      private File content;
      private File en;
      public EngineV1(args) {
         this.content = new File("/some/path");
         this.en = new File("/some/path");
      }
      public static void main(String[] args) {
          new EngineV1(args).run();
      }
  
      public Integer run() {
          // some logic...
          somejar.evaluateSpeed();
      }
  }
  
  public class EngineV2 implements IEngine {
      private File content;
      private File en;
      public EngineV2(args) {
         this.content = new File("/some/path");
         this.en = new File("/some/path");
      }
      public static void main(String[] args) {
          new EngineV2(args).run();
      }
  
      public Integer run() {
          // some logic...
          somejar.evaluateSpeed();
      }
  }
  </code></pre>
  
  <p>When I go to run the main class I get:</p>
  
  <pre><code>Exception in thread "main" java.lang.InstantiationException: com.engine.na.EngineV1
      at java.lang.Class.newInstance(Class.java:427)
      at com.engine.na.MainClass.main(MainClass.java:23)
  Caused by: java.lang.NoSuchMethodException: com.engine.na.EngineV1.&lt;init&gt;()
      at java.lang.Class.getConstructor0(Class.java:3082)
      at java.lang.Class.newInstance(Class.java:412)
      ... 1 more
  </code></pre>
  
  <p>Why do I get this error? How to solve for this? </p>