I have a bean class on a Client side that stores user input data and send it through a socket to server. Server has identical bean class.
Server receives object, but when I try to assign what was received to an instance of the bean class, it results in following error:
java.lang.ClassCastException: ie.gmit.sw.client.methods.Client cannot be cast to ie.gmit.sw.server.methods.Client
Class with an error:
public class DriveableImpl implements Driveable{
private Client client;
private ObjectOutputStream out;
private ObjectInputStream in;
public DriveableImpl() {
client = new Client();
}
// Method that receives connection socket and open in/out streams for current session
@Override
public void connect(Socket socket){
try {
out = new ObjectOutputStream(socket.getOutputStream());
in = new ObjectInputStream(socket.getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public boolean login() throws Exception {
// Program crash here
client = (Client) in.readObject();
System.out.println(client.toString());
return false;
}
}
I use InvocationHandler to invoke methods implemented in class above:
public class MethodInvoker implements InvocationHandler{
private Object returnObject = null; // object that will hold any returns from invoked methods
private final Driveable userInterface;
protected MethodInvoker(Driveable ui) {
this.userInterface = ui;
}
public Object invoke(Object proxy, Method method, Object[] args)
throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException{
System.out.println("BEFORE");
returnObject = method.invoke(userInterface, args);
System.out.println(method.getName());
System.out.println("AFTER");
return returnObject; // could problem be possibly here?
}
}
I am really not sure what's going on here, as it works in simple design of a Client-Server app. I am posting, in my opinion, program parts that are relevant to an error, but I will modify post if any requests occur.
Thank you!