title: NotBoundException on localhost
body: <p>I have a RMI server running on the localhost, exporting an object of type <code>Message</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>try {
      MessageServer obj = new MessageServer();
      Message stub = (Message) UnicastRemoteObject.exportObject(obj, 0);
      Registry registry = LocateRegistry.getRegistry();
      registry.bind("M", stub);
  } catch (RemoteException e) {
  } catch (AlreadyBoundException e) {
  }
  </code></pre>
  
  <p>Then I want to start a client and get the stub for this object. It seems that the registry is found but then in the <code>try</code> block a <code>NotBoundException</code> is thrown:</p>
  
  <blockquote>
    <p>java.rmi.NotBoundException: M
        at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:136)
        at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
        at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
        at sun.rmi.transport.Transport$1.run(Transport.java:177)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)
        at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
        at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
        at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
        at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
        at rmitest.MessageClient.main(MessageClient.java:23)</p>
  </blockquote>
  
  <pre class="lang-java prettyprint-override"><code>public static void main(String args[]) {
          //String host = "localhost";
          Registry registry;
          Message stub = null;
          try {
              registry = LocateRegistry.getRegistry();
              stub = (Message) registry.lookup("M"); //NotBoundException thrown here
          } catch (NotBoundException ex) {
          } catch (AccessException ex) {
          } catch (RemoteException ex) {
          }
          try {
              stub.insert("TestString"); //NullPointerException here
          } catch (RemoteException ex) {
          }
  
  }
  </code></pre>
  
  <p>Why is <code>"M"</code> not found? Both server and client are started inside Netbeans, the registry is started via terminal beforehand.</p>