Results 1 to 3 of 3
Thread: java.rmi.NotBoundException
- 12-09-2008, 06:00 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 17
- Rep Power
- 0
java.rmi.NotBoundException
I am trying to set up a server / client connection and I am getting the following error message on output:
java.rmi.NotBoundException: atmfactory
at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl. java:106)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknow n Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(Unicas tServerRef.java:386
)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:250)
at sun.rmi.transport.Transport$1.run(Transport.java:1 59)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport. java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:5
35)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run0(TCPTranspor
t.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport
.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExec
utor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor
.java:908)
at java.lang.Thread.run(Thread.java:619)
at sun.rmi.transport.StreamRemoteCall.exceptionReceiv edFromServer(Unknow
n Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unk nown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
This is the Server code
This is the client codeJava Code:package cscie160.hw5; import java.rmi.*; public class Server { public static void main(String[] args) { try { // Create and install a security manager //System.setSecurityManager(new RMISecurityManager()); ATMFactoryImpl atmfactory = new ATMFactoryImpl(); Naming.rebind("//localhost/atmfactory", atmfactory); System.out.println("ATMFactory is bound in regsitry"); } catch (Exception e) { System.out.println("Server err: " + e.getMessage()); e.printStackTrace(); } } }
The Server seems to be running fine as I get the following output when I run the Server:Java Code:package cscie160.hw5; import java.net.MalformedURLException; import java.rmi.Naming; import java.rmi.NotBoundException; import java.rmi.RemoteException; import java.rmi.UnknownHostException; public class Client { public static void main(String[] args) { ATM atm = null; try { ATMFactory factory = (ATMFactory)Naming.lookup("//localhost/atmfactory"); atm = factory.getATM(); } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (NotBoundException nbe) { nbe.printStackTrace(); } catch (UnknownHostException uhe) { uhe.printStackTrace(); } catch (RemoteException re) { re.printStackTrace(); } if (atm!=null) { try { // get initial account balance System.out.println("Initial Balances"); System.out.println("Balance(0000001): "+atm.getBalance(0000001)); System.out.println("Balance(0000002): "+atm.getBalance(0000002)); System.out.println("Balance(0000003): "+atm.getBalance(0000003)); System.out.println(); // make $1000 depoist in account 0000001 and get new balance System.out.println("Depositting(0000001): 1000 "); atm.deposit(0000001, 1000); System.out.println("Balance(0000001): "+atm.getBalance(0000001)); // make $100 withdrawal from account 0000002 and get new balance System.out.println("Withdrawing(0000002): 100 "); atm.withdraw(0000002, 100); System.out.println("Balance(0000002): "+atm.getBalance(0000002)); // make $500 deposit in account 0000003 and get new balance System.out.println("Depositting(0000003): 500 "); atm.deposit(0000003, 500); System.out.println("Balance(0000003): "+atm.getBalance(0000003)); // get final account balance System.out.println(); System.out.println("Final Balances"); System.out.println("Balance(0000001): "+atm.getBalance(0000001)); System.out.println("Balance(0000002): "+atm.getBalance(0000002)); System.out.println("Balance(0000003): "+atm.getBalance(0000003)); } catch (RemoteException re) { System.out.println("An exception occurred while communicating with the ATM"); re.printStackTrace(); } } } }
Creating an ATMFactoryImpl instance...
ATMFactory is bound in registry
Why am I getting this error?Last edited by soxfan714; 12-09-2008 at 06:09 AM.
- 12-09-2008, 06:09 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you define ATMFactoryImpl class correctly? Is that a default package?
- 12-09-2008, 06:12 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 17
- Rep Power
- 0
I think I defined ATMFactoryImpl class correctly but I could be wrong. This is what I have
Java Code:package cscie160.hw5; import java.rmi.*; import java.rmi.server.UnicastRemoteObject; public class ATMFactoryImpl extends UnicastRemoteObject implements ATMFactory { public ATMFactoryImpl() throws RemoteException { System.out.println("Creating an ATMFactoryImpl instance..."); } /** * getATM() - retruns reference to an ATM object * */ public ATM getATM() throws RemoteException{ ATM myATM = new ATMImpl(); return myATM; } }


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks