Hi all,
I recently had a topic submitted to this forum (Sept 17th, 2002 Subject: ClassCastException problem).
The following is an extract:
I have a bean called Body which is in a package
com.test.config.model.bean. It consists of three
private strings and their getter and setter methods.
I also have a class called Container which is in a package com.test.server.
This class has a getBodyContainer method which returns a vector of Bodys.
I also have a
servlet called
Test which is in a package
called com.test.config.controller.servlet
Test instantiates a Container object and calls the getBodyContainer method. i.e.
Vector bodys = container.getBodyContainer();
for (int i = 0; i < bodys.size(); i++)
{
Object object = bodys.elementAt(i);
Body body = (Body) object;
}
I get a class cast exception on the line:
Body body = (Body) object;
Why does this happen ?
I have now fixed the problem but I am still confused.
I had both client and server classes in my classpath.
I am using Jakarta
Tomcat 4.0 as my servlet engine.
All of the classes mentioned above are on the server side except for the body class whose class file was on the client side.
When I moved it from the client to the server side the ClassCastException dissappeared.
Why does this movement resolve my problem ?
Is there a subtle difference between client and server side objects in how they are accessed ?
Any help would be greatly appreciated.
Regards,
Damian.