title: Cannot instantiate class from interface
body: <p>I have the following interface in the application I am building:</p>
  
  <pre><code>package sistemata;
  
  public interface PaymentgatewayAdapter
  {   
      public String postPayment(String a);
  }
  </code></pre>
  
  <p>And the following class implements it:</p>
  
  <pre><code>public class PaypalAdapter implements PaymentgatewayAdapter
  {
      public String postPayment(String a)
      {
  
          String payAmount;
          String transactionOutcome;
          String response;
          payAmount = a;
  
          Paypal_sim systemGN = new Paypal_sim();
          System.out.println("v adaptera" + a);
          //Simulerar att data skickas till externa systemet
          response = systemGN.transferSaleData(payAmount);
  
          if (response == "OK")
          {
              transactionOutcome = "OK";
          }
          else
          {
              transactionOutcome = "Invalid data sent to MasterCard.";
          }
  
          return transactionOutcome;
          //------------------------------
      }
  }
  </code></pre>
  
  <p>There is a second, almost identical class called Payson, but it is not used. 
  This interface is part of a <code>ServicesFactory</code>:</p>
  
  <pre><code>package sistemata;
  
  public class ServicesFactory
  {
      private static ServicesFactory instance;
      private PaymentgatewayAdapter paymentAdapter;
  
      private String className2;
  
      public static synchronized ServicesFactory getInstance()
      {
          instance = new ServicesFactory();
          return instance;
      }
  
  
      public PaymentgatewayAdapter getPaymentAdapter(String className2) 
      {
          this.className2 = className2;
  
          if (paymentAdapter == null)
          {
              try
              {
                  paymentAdapter = (PaymentgatewayAdapter)
                          Class.forName(className2).newInstance();
              }
              catch (Exception e)
              {
                  System.out.println("ERROR: Cannot instantiate: " +
                          className2 + ".");
                  e.printStackTrace();
                  System.exit(1);
              }
          }
          return paymentAdapter;  
      }
  }
  </code></pre>
  
  <p>The method <code>getPaymentAdapter</code> is called in <code>Account</code> class, like this:</p>
  
  <pre><code>else if (paymentMethod == 0)
  {
      System.out.println("The payment method is PayPal INC");
      String className = "PaypalAdapter";
      paymentAdapter = ServicesFactory.getInstance().getPaymentAdapter(className);
  }
  </code></pre>
  
  <p>Whenever I call:</p>
  
  <pre><code>paymentAdapter = ServicesFactory.getInstance().getPaymentAdapter(className);
  </code></pre>
  
  <p>I get the error that is thrown in  <code>System.out.println("ERROR: Cannot instantiate:.</code>
  Whatever I try, I cannot work around this and I cannot find solution. I will be thankful for some help with this code, or even suggestions to hardcode. </p>
  
  <pre><code>java.lang.ClassNotFoundException: PaymentgatewayAdapter
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Unknown Source)
      at sistemata.ServicesFactory.getPaymentAdapter(ServicesFactory.java:26)
      at sistemata.Account.makePayment(Account.java:56)
      at sistemata.MainSystem.main(MainSystem.java:71)
  </code></pre>