ClassCast Exception

I have the following error...I'm working on someone else's project (improvement) so I met a lot of bottlenecks...this is one of them:

chatObj = (ChatObj) in.readObject();

when I run the whole project, it flags a classcastexception at this line.

in case u guys are wondering what chatObj is, the previous guys declared this:

protected ChatObj chatObj;

and ChatObj is actually a seperate java file where it implementsSerializable

Any help is appreciated...

[522 byte] By [EverteMaxa] at [2007-10-1 21:51:44]
# 1
This has nothing to do with source code. At runtime, the serialized object on the stream in is not a ChatObj.Try:Object o = in.readObject();System.err.println(o.getClass())
AlexHudsa at 2007-7-13 7:55:01 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
If I do that, then I can't call the methods defined in the class...like their next line:chatObj.getMessage();it will render this line of code useless
EverteMaxa at 2007-7-13 7:55:01 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

You misunderstood. I just meant print out the class of the object on the stream so that you can figure out exactly what you've got, and why it isn't a ChatObj.

(Besides, if you don't actually have a ChatObj instance, there's no code that will let you call methods on it anyway!!!)

Can you post the exception stacktrace that you get with your ClassCastException? That should tell us what's wrong too.

AlexHudsa at 2007-7-13 7:55:01 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4
That was another problem too...java.lang.ClassCastExceptionat com.nostalgia.engine.ChatConnection.run(ChatConnection.java:60)this is it...I even used the printStackTrace method, this is all I get...
EverteMaxa at 2007-7-13 7:55:01 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 5
A complete stack trace and code snippet would help.
sduraia at 2007-7-13 7:55:01 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...