title: ClassCastException : Proxy0 cannot be cast to interfaces.Patient
body: <p>Hi i keep getting this error and don't know why</p>
  
  <pre><code>java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to interfaces.Patient
      at main.RemoteObjects.&lt;init&gt;(RemoteObjects.java:15)
      at DRV_GUI.&lt;init&gt;(DRV_GUI.java:49)
      at Main.main(Main.java:13)
  </code></pre>
  
  <p>I have a server application starting like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>import java.rmi.Naming;
  import java.rmi.registry.LocateRegistry;
  import java.rmi.registry.Registry;
  
  public class MainServer {
  
  PatientImpl patient = null;
  LoginImpl login = null;
  
  public MainServer(String[] args) {
      // TODO constructor
      System.out.println("Ich bin der Konstruktor von Main.java");
  }
  
  public static void main(String[] args) {
      MainServer server = new MainServer(args);
      server.start();
  }
  
  private void start() {
      try {
          patient = new PatientImpl();
          login = new LoginImpl();
          Registry registry = LocateRegistry.createRegistry(1099);
          Naming.rebind("patient", patient);
          Naming.rebind("login", login);
      } catch (Exception ex) {
          ex.printStackTrace();
      }
  }
  }
  </code></pre>
  
  <p>the patient interface ís the follówing:</p>
  
  <pre class="lang-java prettyprint-override"><code>package interfaces;
  
  import java.rmi.RemoteException;
  import java.util.LinkedHashMap;
  
  public interface Patient {
      public LinkedHashMap&lt;String, LinkedHashMap&lt;Integer, LinkedHashMap&lt;String, Object&gt;&gt;&gt; patientSuchen(String id, User user) throws RemoteException;
      public boolean kostenzusageSpeichern (String id, User user) throws RemoteException;
      public boolean aufnahmeStornieren (String id, User user) throws RemoteException;
      public boolean aufnahmeAendern (String id, User user) throws RemoteException;
      public boolean entlassungStornieren (String id, User user) throws RemoteException;
      public boolean entlassungAendern (String id, User user) throws RemoteException;
      public boolean eingangEntlassungsStatistikStorieren (String id, User user) throws RemoteException;
      public boolean eingangEntlassungsStatistikAendern (String id, User user) throws RemoteException;
      public LinkedHashMap&lt;String, LinkedHashMap&lt;String, Object&gt;&gt; getVeraengerunglUnterbrechung(String id, String table, User user) throws RemoteException;
      public boolean setVeraengerunglUnterbrechung(String id, String table, User user) throws RemoteException;
  }
  </code></pre>
  
  <p>its the same on client and server side also the package name is the same;</p>
  
  <p>here the RemoteObjects.java code:</p>
  
  <pre><code>    package main;
  
      import interfaces.*;
      import java.rmi.Naming;
  
      public class RemoteObjects {
          Login login;
          public Patient patient;
          public String remoteIP = "127.0.0.1";
  
          /*
           * secrets[0] = PatientI
           */
          public RemoteObjects() {
          try {
              String name = "rmi://" + remoteIP + ":" + 1099 + "/";
              patient = (Patient) Naming.lookup(name + "patient");
              login = (Login) Naming.lookup(name + "login");
          } catch (Exception ex) {
              ex.printStackTrace();
          }
          }
  
      }
  </code></pre>
  
  <p>what am I doing wrong? would be very happy if somebody has an idea</p>