Search code examples
javaswinguser-interfacermi

java.rmi.NotBoundException


i have written small RMI chat program and its compiling properly.but when i try to run Client program it results exception "java.rmi.NotBoundException - ServerInterface" Server program runs without any errors..please help me to solve this.

here is some of Client code

public static void main (String[] args)
{
String address = "rmi://localhost/ServerInterface";
try
{
ServerInterface si= (ServerInterface) Naming.lookup(address);
new Thread(new Client(si)).start();
}
catch (Exception e)
{
System.err.println(e.toString()) ;
}
}

Solution

  • A NotBoundException is thrown if an attempt is made to lookup or unbind in the registry a name that has no associated binding.

    What is your server code look like? This exception you are having most likely caused by server not set up properly.

    I think in your server code you are bind with name ChatServer

     Naming.rebind("ChatServer", new Server());
    

    But in your client code you are using ServerInterface name

    String address = "rmi://localhost/ServerInterface";
    

    For more details Naming