I have found the solution: 1)Dont define the Class in the two sides )cliet & server, Just define a class on the Client. 2)Import the class in the server side
import clientSide.Message;
and that's is
Question
I know that this question has been asked many times but any of the answers help me to get ride of the problem. I am working on a IM program using Java (netbeans)...
I have a class called "message" in the client side, and I pass the class from client to server, and in the server there is a class called messege similar to messege class on the client side.
I uses ObjectInputStream / ObjectOutputStream to send/receive the Class from/to the server, and the server program tell: ClassNotFound exception and point to message class that exist in the client side.
how to solve this problem.
points: - the Class Message exist on the two sides, and not missed! - I passes an object not a class - the classes are Serializable - I used casting :
msg= (message) SomeObjectInputStream.ReadObject();
Here is the exact error messages :
Oct 05, 2013 4:32:40 PM EIQserver.EIQserver run SEVERE: null
java.lang.ClassNotFoundException: RandomSend.Message
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:622)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1593)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at EIQserver.EIQserver.run(EIQserver.java:55)
My class:
public class Message implements Serializable {...}
and the error is pointing here:
fromuser=(Message) OIS.readObject();
Important: I also Defined the class in the same file of the client class and in the server class (instead of separated files), but still get the same Exception!!!!
La solution 2
I have found the solution: 1)Dont define the Class in the two sides )cliet & server, Just define a class on the Client. 2)Import the class in the server side
import clientSide.Message;
and that's is
Autres conseils
Looks like there is a typo in your code. "message" on the client and "massege" on the server.