Question

I was trying to run the Hello World RMI example from the Oracle page, but I keep getting errors.

the error I keep getting is

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)

Here is the code as taken directly from the site that I used:

The Hello Interface:

package example.hello;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Hello extends Remote {
    String sayHello() throws RemoteException;
}

This is what my server class:

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();
        }
    }
}

Client 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();
        }
    }
}

Any feedback is greatly appreciated!

Was it helpful?

Solution

The Registry isn't running. Either start the rmiregistry tool, or change getRegistry() to createRegistry().

It's curious, as some JVM must have been listening on port 1099, but not with a Registry running in it. Normally no Registry causes a java.rmi.ConnectException.

OTHER TIPS

I think your interface method should have public modifier

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top