| Author |
RMI classcast exception
|
Deepika Gupta
Greenhorn
Joined: Oct 02, 2008
Posts: 5
|
|
I am getting this exception at the server side.Can anybody tell me what could be the problem? java.lang.ClassCastException: cannot assign instance of ApplicationServer_Stub to field ServerSession.aAppServer of type ApplicationServer in instance of ServerSession Thanks Deepika
|
 |
Nitesh Kant
Bartender
Joined: Feb 25, 2007
Posts: 1638
|
|
Hi Deepika, Welcome to javaranch. One gets a ClassCastException when you try to cast an instance to a type that it does not belong to. You will also have a stack trace that will tell you exactly where the problem is. If you can not, please post the stack trace and the relevant code.
|
apigee, a better way to API!
|
 |
Deepika Gupta
Greenhorn
Joined: Oct 02, 2008
Posts: 5
|
|
Thanks Nitesh for the reply Actually I am aware of the fact that ClassCast exception comes when we try to cast a type with some wrong one.But i am not getting it in this case of rmi.The full trace is given below which happens at the server From the client when i am calling this method. It fails at lApplicationServer.mGetUserSessions().iApplicationServer is a remote interface. public static boolean ActiveSession(String name){ iApplicationServer lApplicationServer = mGetApplicationServer(); try{ Vector lVecSessions = lApplicationServer.mGetUserSessions(); return true; } }catch(Exception e) { System.out.println("Exception in ActiveSession: "+e.getMessage()); e.printStackTrace(); } return false; } Now at the server side,this code will be executed public java.util.Vector mGetUserSessions() throws RemoteException { Vector lVecSessions = new Vector(); synchronized (aSessions) { try { for (int i = 0; i < aSessions.size(); i++) { iServerSession lServerSession = (iServerSession)aSessions.elementAt(i); cUserSession lUserSession = new cUserSession(lServerSession); lVecSessions.add(lUserSession); } } catch (Exception pEx) { } } return lVecSessions; } iServerSession is also a remote interface. and ServerSession implements it. It has a field ApplicationServer aAppServer.iApplicationServer is also a remote interface and AppliactionServer implements it. java.lang.ClassCastException: cannot assign instance of ApplicationServer_Stub to field ServerSession.aAppServer of type ApplicationServer in instance of ServerSession Exception in ActiveSession: cannot assign instance of ApplicationServer_Stub to field ServerSession.aAppServer of type ApplicationServer in instance of ServerSession java.lang.ClassCastException: cannot assign instance of ApplicationServer_Stub to field ServerSession. aAppServer of type ApplicationServer in instance of ServerSession at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStre amClass.java:1977) at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:11 57) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:19 18) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1 713) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:19 12) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1 713) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299) at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1628) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1293) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:19 12) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1 713) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339) at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:290) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:139) at ApplicationServer_Stub.mGetUserSessions( Unknown Source) at RepositoryContainer.ActiveSession(Reposit oryContainer.java:81) at UpdateDataThread.run(UpdateDataThread.java:71) Thanks
|
 |
 |
|
|
subject: RMI classcast exception
|
|
|