title: Java RMI class com.sun.proxy.$Proxy0 cannot be cast to class client.MessageServerInt
body: <p>Edit: So even after changing them all to the same package, still getting the error. So not package related.</p>
  
  <p>I'm doing an RMI client/server project for school. The teacher says the Server/Client must be in different packages, which I believe is why I'm having this issue. Just gonna leave out error handling (try/catch) for space. Server runs fine. I think the server and client being in two different packages is causing issues, but unsure how to actually fix it as the server and client are in two different locations (machines).</p>
  
  <p>Full error message is</p>
  
  <pre><code>java.lang.ClassCastException: class com.sun.proxy.$Proxy0 cannot be cast to class client.MessageServerInt (com.sun.proxy.$Proxy0 and client.MessageServerInt are in unnamed module of loader 'app')
  </code></pre>
  
  <p>Interface</p>
  
  <pre><code>package server;
  import java.rmi.*
  
  public interface MessageServerInt extends Remote {
  public boolean auth();
  }
  </code></pre>
  
  <p>Server</p>
  
  <pre><code>package server;
  import java.rmi.*;
  import java.rmi.server.*;
  class Server extends UnicastRemoteObject implements MessageServerInt {
  public Server() throws RemoteException {
  
  }
  
  public boolean auth() {
  return true;
  }
  
  public static void main(String args[]) {
  MessageServerInt srv= new Server();
  Naming.rebind("rmi://localhost:1099/Server", srv);
  }
  }
  </code></pre>
  
  <p>Client</p>
  
  <pre><code>package client;
  import java.rmi.*;
  import server.MessageServerInt;
  
  public class Client {
  
  public static void main(String args[]) {
  MessageServerInt stub = (MessageServerInt)Naming.lookup("//localhost:1099/server");
  }
  
  }
  </code></pre>