Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

RMI classcast exception

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Deepika Gupta
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic