Results 1 to 2 of 2
- 03-02-2013, 07:37 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 20
- Rep Power
- 0
RMI - ClassCastException - Proxy cannot be cast
Hello, i'm currently switching to RMI for networking in my application, i have followed some tutorials, read some on Oracles RMI pages and i belive i understand the concept behind it.
I found a example on the net and its working with transmitting Strings. however when i try to send my own object it get the error:
Googling for this error tells me from what i can understand that i have not implemented the interface in my class. But i have (Fag implements FagInterface).Java Code:HelloClient exception: java.lang.ClassCastException: sun.proxy.$Proxy0 cannot be cast to saqib.rasul.server.Fag java.lang.ClassCastException: sun.proxy.$Proxy0 cannot be cast to saqib.rasul.server.Fag at sun.proxy.$Proxy0.returnFag(Unknown Source) at saqib.rasul.server.dd.main(dd.java:19)
So yeh, i have no idea why i get this error, and what it means.
Client.java
Breaks on: System.out.println(fag.returnFag());Java Code:package saqib.rasul.server; import java.rmi.Naming; public class Client { /** * Client program for the "Hello, world!" example. * @param argv The command line arguments which are ignored. */ public static void main (String[] argv) { try { // HelloInterface hello = (HelloInterface) Naming.lookup ("//localhost/Hello"); FagInterface fag = (FagInterface) Naming.lookup("//localhost/Fag"); // System.out.println (hello.say()); System.out.println(fag.returnFag()); } catch (Exception e) { System.out.println ("HelloClient exception: " + e); e.printStackTrace(); } } }
Server.java
FagInterface.javaJava Code:package saqib.rasul.server; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; public class Server { /** * Server program for the "Hello, world!" example. * @param argv The command line arguments which are ignored. */ public static void main (String[] argv) { try { java.rmi.registry.LocateRegistry.createRegistry(1099); System.out.println("RMI registry ready."); //Naming.rebind ("Hello", new Hello ("Hello, world!")); String name = "Fag"; FagInterface engine = new Fag("Universi"); FagInterface stub = (FagInterface) UnicastRemoteObject.exportObject(engine, 0); Registry registry = LocateRegistry.getRegistry(); registry.rebind(name, stub); System.out.println ("Hello Server is ready."); } catch (Exception e) { System.out.println ("Hello Server failed: " + e); } } }
Fag.javaJava Code:package saqib.rasul.server; import java.rmi.Remote; import java.rmi.RemoteException; public interface FagInterface extends Remote{ public Fag returnFag() throws RemoteException; }
ThanksJava Code:package saqib.rasul.server; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; import java.util.ArrayList; /** * * @author Per-Arne * @description Simple class which contains all subjects (fag) in a single course (kurs). The way this class works is that it takes a ArrayList with subject for a whole week. Then this week is added to another ArrayList which then is the grand total of subjects. */ public class Fag implements FagInterface{ private static final long serialVersionUID = 1L; public String fagName; public ArrayList<ArrayList<FagTime>> weeks; private Fag fag; public Fag(String fagName) throws RemoteException{ this.fag = this; } /** * @param week - Contains a whole week with subjectData, this is added to this course. */ public void addWeek(ArrayList<FagTime> week) throws RemoteException{ weeks.add(week); } public Fag returnFag() throws RemoteException { return fag; } }
Driiper
- 03-04-2013, 01:56 AM #2
Member
- Join Date
- Apr 2012
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
Caught: java.lang.ClassCastException: java.util.ArrayList cannot be cast to Point4D
By proggrammer in forum New To JavaReplies: 1Last Post: 06-19-2012, 02:55 AM -
openConnection(Proxy proxy) question
By Dark in forum New To JavaReplies: 8Last Post: 12-31-2011, 01:15 PM -
java.lang.ClassCastException: myclass cannot be cast to myclass
By paulusi in forum New To JavaReplies: 2Last Post: 01-21-2011, 06:22 AM -
Http - proxy or non-proxy ?
By Shiv in forum NetworkingReplies: 0Last Post: 04-11-2009, 08:07 AM -
ClassCastException
By paulsim in forum Java AppletsReplies: 2Last Post: 08-21-2008, 02:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks