title: RMI no such object exception
body: <p>I was trying to run the Hello World RMI example from the Oracle page, but I keep getting errors. </p>
  
  <p>the error I keep getting is</p>
  
  <blockquote>
    <p>Server exception: java.rmi.NoSuchObjectException: no such object in
    table java.rmi.NoSuchObjectException: no such object in table     at
    sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)
      at
    sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:378)    at
    sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)   at
    example.hello.Server.main(Server.java:26)</p>
  </blockquote>
  
  <p>Here is the code as taken directly from the site that I used:</p>
  
  <p>The Hello Interface:</p>
  
  <p>package example.hello;</p>
  
  <pre><code>import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  public interface Hello extends Remote {
      String sayHello() throws RemoteException;
  }
  </code></pre>
  
  <p>This is what my server class:</p>
  
  <pre><code>package example.hello;
  
  import java.rmi.registry.Registry;
  import java.rmi.registry.LocateRegistry;
  import java.rmi.RemoteException;
  import java.rmi.server.UnicastRemoteObject;
  
  public class Server implements Hello {
  
      public Server() {}
  
      public String sayHello() {
          return "Hello, world!";
      }
  
      public static void main(String args[]) {
  
      try {
          Server obj = new Server();
          Hello stub = (Hello) UnicastRemoteObject.exportObject(obj,0);
  
          // Bind the remote object's stub in the registry
          Registry registry = LocateRegistry.getRegistry("localhost");
          registry.bind("Hello", stub);
  
          System.err.println("Server ready");
          } catch (Exception e) {
              System.err.println("Server exception: " + e.toString());
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Client code:</p>
  
  <pre><code>package example.hello;
  
  import java.rmi.registry.LocateRegistry;
  import java.rmi.registry.Registry;
  
  public class Client {
  
      private Client() {}
  
      public static void main(String[] args) {
  
          String host = "localhost";
          try {
              Registry registry = LocateRegistry.getRegistry(host);
              Hello stub = (Hello) registry.lookup("Hello");
              String response = stub.sayHello();
              System.out.println("response: " + response);
          } catch (Exception e) {
              System.err.println("Client exception: " + e.toString());
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Any feedback is greatly appreciated!</p>