Search code examples
javaserializationclassnotfoundexceptionobjectinputstream

ClassNotFoundException in ObjectInputStream.readObject()


I'm trying to cast an object passed by my client application to an object of identical class in my server application.

The error I'm currently receiving in my server application is:

mei 02, 2012 11:44:43 PM server.UserThread process
SEVERE: null
java.lang.ClassNotFoundException: client.User

The object is being received by the server via Socket -> ObjectInputStream.

So I was wondering if you guys could help me cast the client.User class to my Server.User class. The only thing that works is placing the packages inside 1 project and then defining the exact location of the class.

Code can always be supplied.


Solution

  • cast the client.User class to my Server.User class

    You can't. They aren't the same class. They are in different packages. They are different. If you want to share a class between server and client, you have to share a single .class file. That might imply creating a third package for shared stuff.