title: RMI NotSerializableException although it's a remote object
body: <p>I'm writing a small RMI based Chat application.</p>
  
  <p>The idea is: the Client registers himself on the Server, and everytime the server receives a message from a client, he pushes this message to all other clients.</p>
  
  <p>But I receive a NotSerializableException although, the object, I'm passing as a method parameter implements the Remote interface.</p>
  
  <p>Here is some code:
  (The problematic part is the <code>this</code> parameter in <code>this.chatServ.registriereClient(this);</code> (ClientChat Implementation))</p>
  
  <p>The (ClientChat)interface:</p>
  
  <pre><code>public interface ChatClient extends Remote
  {
  
  }
  </code></pre>
  
  <p>(ClientChat)Implementation:</p>
  
  <pre><code>public class ChatClientImpl implements ChatClient
  {
  
      ChatServer chatServ;
      String clientName;
  
      public ChatClientImpl(String clientName, ChatServer chatServ) {
          this.chatServ = chatServ;
          this.clientName = clientName;
          try {
              this.chatServ.registriereClient(this);
          } catch (RemoteException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>(ServerChat) Interface</p>
  
  <pre><code>public interface ChatServer extends Remote
  {
          void registriereClient(ChatClient client) throws RemoteException;
  
  }
  </code></pre>
  
  <p>(ServerChat) Implementation</p>
  
  <pre><code>public class LobbyChatServerImpl implements ChatServer
  {
  
      ArrayList&lt;ChatClient&gt; clientListe = null;
  
      @Override
      public void registriereClient(ChatClient client) {
          System.out.println("Client registriert");
          this.clientListe.add(client);
      }
  }
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>  public static void main(String[] args) {
          ChatServer lobbyChatServer = null;
          try {
              Registry registry = LocateRegistry.getRegistry(Server.RMI_PORT);
              lobbyChatServer = (ChatServer) registry.lookup("LobbyChatServer");
  
          } catch (RemoteException e) {
              e.printStackTrace();
          } catch (NotBoundException e) {
              e.printStackTrace();
          }
  
          ChatClient lobbyChat = new ChatClientImpl(name, lobbyChatServer);
    }
  </code></pre>
  
  <p>Server:</p>
  
  <pre><code>    public static void main(String[] args) {
          try {
              if (System.getSecurityManager() == null) {
                  System.setSecurityManager(new RMISecurityManager());
              }
  
              Registry registry = LocateRegistry.getRegistry(RMI_PORT);
  
              ChatServer lobbyChatStub = (ChatServer)UnicastRemoteObject.exportObject(new LobbyChatServerImpl(), 0);
              registry.bind("LobbyChatServer", lobbyChatStub);
  
          } catch (RemoteException e) {
              e.printStackTrace();
          } catch (AlreadyBoundException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>Exception:</p>
  
  <pre><code>java.rmi.MarshalException: error marshalling arguments; nested exception is: 
      java.io.NotSerializableException: de.XX.Chat.ChatClientImpl
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:156)
      at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
      at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
      at $Proxy0.registriereClient(Unknown Source)
      at de.XX.Chat.ChatClientImpl.&lt;init&gt;(ChatClientImpl.java:19)
      at de.XX.Client.main(Client.java:49)
  Caused by: java.io.NotSerializableException: de.XX.Chat.ChatClientImpl
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
      at sun.rmi.server.UnicastRef.marshalValue(UnicastRef.java:292)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:151)
      ... 5 more
  </code></pre>
  
  <p>As already said, I wonder why i get this kind of Exception, although ChatClientImpl is already Remote.</p>
  
  <p>Hope you can help me:)</p>