This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes  java.rmi.NotBoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark " java.rmi.NotBoundException" Watch " java.rmi.NotBoundException" New topic
Author

java.rmi.NotBoundException

H Padia
Greenhorn

Joined: Nov 18, 2009
Posts: 8
Hello,

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.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 client.Client.main(Client.java:29)


I tried going through a few forums, but not of much luck.

Your help will be appreciated.

Thank you.

-H
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2563
    
    9

Welcome to the Ranch.

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


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
H Padia
Greenhorn

Joined: Nov 18, 2009
Posts: 8
Hello K!
Thank you for your post. The Server seems to work fine. The following is my code for server.

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2563
    
    9

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
H Padia
Greenhorn

Joined: Nov 18, 2009
Posts: 8
Hello K!

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.rmi.NotBoundException