I'm trying to send an object trough sockets, but when I want to read the object in the client I got java.lang.ClassCastException.
My object is the following and I have it in both projects(Server and Client).
class Data implements Serializable{
int height;
int width;
int max;
int zoom;
int start;
int end;
int xMove;
int yMove;
public Data(int height, int width, int max, int zoom, int start, int end, int xMove, int yMove){
this.height = height;
this.width = width;
this.max = max;
this.zoom = zoom;
this.start = start;
this.end = end;
this.xMove = xMove;
this.yMove = yMove;
}
}
The sending part:
try{
Data dataToSend = new Data(height, width, max, zoom, start, end, xMove, yMove);
out.writeObject(dataToSend);
}
The receiver part:
try{
InputStream is = socket.getInputStream();
Data dataToRead = (Data)ois.readObject();
}
And the error message:
java.lang.ClassCastException: lab05_server.Data cannot be cast to lab05_kliens.Data
I tried everything with the same result. I can't find my mistake.
Thank you for any help.