ClassCastException

HI

I have declared an object(which implements java.io.Serializable) and the number of objects of that type i am putting into a Vector. I am passing the vector to a function through remote call. which accepts this vector as List and when i am trying to cast the objects in the List to its original type, i am able to typecast the first object and i am getting java.lang.ClassCastException for the rest of the objects. One STRANGE OBSERVATION is , when i try to get the class name of the object it is returning the proper name , but when i use instanceof operator it is returing me false. WHY is this SO?

Thanks In Advance,

U can reply me back at mailto:nitin_jain@infy.com

Nitin

[716 byte] By [cheenujain] at [2007-9-26 2:21:09]
# 1
Could you post some code?
schapel at 2007-6-29 9:25:54 > top of Java-index,Archived Forums,Java Programming...
# 2

> HI

>

> I have declared an object(which implements

> java.io.Serializable) and the number of objects of

> that type i am putting into a Vector. I am passing the

> vector to a function through remote call. which

> accepts this vector as List and when i am trying to

> cast the objects in the List to its original type, i

> am able to typecast the first object and i am getting

> java.lang.ClassCastException for the rest of the

> objects. One STRANGE OBSERVATION is , when i try to

> get the class name of the object it is returning the

> proper name , but when i use instanceof operator it is

> returing me false. WHY is this SO?

>

> Thanks In Advance,

> U can reply me back at mailto:nitin_jain@infy.com

> Nitin

Hi Chapel

The code is like this

for the class whose object are put into the list :

/*******************************/

import java.io.Serializable;

public class ACLObject implements Serializable

{

private String accessID;

private String accessType;

private String accessLevel;

private int priority;

ACLObject()

{

}

public String getAccessID()

{

return accessID;

}

public String getAccessType()

{

return accessType;

}

public String getAccessLevel()

{

return accessLevel;

}

public int getPriority()

{

return priority;

}

public ACLObject(String accessID, String accessType, String accessLevel, int priority)

{

this.accessID = accessID;

this.accessType = accessType;

this.accessLevel = accessLevel;

this.priority = priority;

}

public String toString()

{

return "\n This ACL Object consist of : " +

"\n Access ID: " + accessID +

"\n Access Type: " + accessType +

"\n Access Level: " + accessLevel +

"\n Priority: " + priority ;

}

public void setAccessID(String accessID)

{

this.accessID = accessID;

}

public void setAccessType(String accessType)

{

this.accessType = accessType;

}

public void setAccessLevel(String accessLevel)

{

this.accessLevel = accessLevel;

}

public void setPriority(int priority)

{

this.priority = priority;

}

}

/******************************************/

the portion of the other class where its getting failed.

/*******************************************/

for (int i= 0 ; i< tempList.size(); i++)// where tempList = List of ACLObject

{

ACLObject a = (ACLObject)tempList.get(i);

}

/****************************************/

FOR THE FIRST OBJECT IN THE LIST THE CODE IS WORKING FINE BUT FOR 2ND OBJECT AND ABOVE ITS GIVING THE ClassCastException. IF I AM CREATING THE LIST IN THE SAME CLASS WHERE I AM FETCHING THE OBJECT FROM THE LIST THE CODE IS WORKING FINE. WHAT CAN BE THE PROBLEM?

Regards

Nitin

cheenujain at 2007-6-29 9:25:54 > top of Java-index,Archived Forums,Java Programming...