This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am trying to create an RMI. I am getting " java.rmi.NotBoundException " error. I am sure that the firewall on server side and the client side are turned off. Also, the /etc/hosts file contain the correct IP address of the server machine.
The following is the code at the client end:
The following is the stact trace:
Client exception: java.rmi.NotBoundException: rmi://ServerMc:1099/Services java.rmi.NotBoundException: rmi://ServerMc:1099/Services at sun.rmi.registry.RegistryImpl.lookup(Unknown Source)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
I tried going through a few forums, but not of much luck.
Ah I see the problem. Your name of the server is wrong. You use "Services" in the server class (line 18). But in your client you are binding to "ServerMc" (line 7). Both of these must be the same.
Now some nitpick. Since you are using RMI, then your Server class should extend UnicastRemoteObject and it should also have a default constructor throwing RemoteException. How about the Services interface? Does it extend Remote interface?
The 2nd nitpick is your registry in your Server class. If you created your registry on line 11 then you really don't need line 17. Or you can simply create the registry on line 17 and remove line 11. Then for line 18, I recommend using rebind rather than bind. Don't ask me why.
If you are in doubt on how to set up the files ... please refer to the RMI Java tutorial
Joined: Nov 18, 2009
It works now. I made the following changes in the Client class:
In the Server class Line 18 "Services" is a name associate with the remote reference, 'stub' in my case. While the "ServerMc" in line 7 of Client class is the name of the Server Machine in my /etc/hosts.