Search code examples
javaexceptionrmi

Java RMI - registry bind call results in NoSuchObjectException


I got an simple program that should make calcPi() avaible over Java-RMI, when I start the programm I get this exception:

java.rmi.NoSuchObjectException: no such object in table
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at server.CalculatePi.main(CalculatePi.java:24)

Here's my code and below the interface:

public class CalculatePi implements ICalculatePi {
    @Override
    public Double calcPi() throws RemoteException{
    return 3.141259;
}

public static void main(String[]args){
    if(System.getSecurityManager()==null){
        System.setProperty("security.policy","file:./security.policy");
    }
    try{

        String name="Pi-Rechner";
        ICalculatePi rechner=new CalculatePi();
        ICalculatePi stub=(ICalculatePi) UnicastRemoteObject.exportObject(rechner, 0);
        Registry myRegistry=LocateRegistry.getRegistry();
        myRegistry.rebind(name,stub);
        System.out.println("Rechner gebunden!");
    }catch(Exception e){
        e.printStackTrace();
    }
}

}

and here's my Interface:

package server;

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

public interface ICalculatePi extends Remote {
    public Double calcPi() throws RemoteException;
}

I followed the tutorial while programming: http://docs.oracle.com/javase/tutorial/rmi/implementing.html

Thanks if someone got a good and easy solution!


Solution

  • You have another RMI process running on your system, exported on port 1099, but it's not an RMI registry. Find that process, kill it, and run an RMI registry (typically the rmiregistry command).