Results 1 to 3 of 3
- 12-09-2008, 09:34 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 17
- Rep Power
- 0
Need Help with Class Cast Exception
I start the rmi registry, then I run the server and everything seems to be fine.
When I run the client, I get this exception:
Exception in thread "main" java.lang.ClassCastException: $Proxy1 cannot be cast
to cscie160.hw5.ATM
at $Proxy0.getATM(Unknown Source)
at cscie160.hw5.Client.main(Client.java:13)
This is the server code
This is the client code:Java Code:package cscie160.hw5; import java.rmi.*; public class Server { public static void main(String[] args) { try { 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(); } } }
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(); } } } }
This is the ATMFactory Code:
Java Code:package cscie160.hw5; import java.rmi.RemoteException; /** * Public Interface ATMFactory * getATM() */ public interface ATMFactory extends java.rmi.Remote{ public ATM getATM() throws RemoteException; }
Any help would be greatly appreciated.
- 12-10-2008, 02:06 AM #2
From your tutorial:
Source: distance education section of Harvard Extension CSCIE160The java.rmi.Naming class provides methods lookup, bind, rebind, unbind and list (returns an array of object name registered on the host: port). The naming service is accessed on a particular host: port combination.
( note the colon is parsing as a smiley so there is an embedded space that is to be removed )Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 11-03-2011, 04:33 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 64
- Rep Power
- 0
Similar Threads
-
Class not found Exception
By surendra in forum Java ServletReplies: 8Last Post: 06-09-2011, 12:52 PM -
class cast exception
By venkatallu in forum New To JavaReplies: 2Last Post: 09-02-2008, 09:50 PM -
How to create your own Exception class
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:40 PM -
Exception Failed to Generate Wrapper Class on WebLogic
By christina in forum New To JavaReplies: 1Last Post: 08-07-2007, 02:15 AM -
Cast Error Caught (change) Class is really: java.lang.String
By barney in forum Advanced JavaReplies: 1Last Post: 08-02-2007, 04:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks