我从java 文档中验证了boolean 和 byte 是可序列化的。根据android 文档,我的类实现了可序列化的接口。我不确定为什么我不断收到异常。我在这里想念什么?类是这样的:
public class msgStruct implements Serializable {
boolean pingPong = false;
int msgId = 0;
byte[] bufferMsg = new byte[100];
}
这在通过套接字发送到服务器之前被序列化,如下所示:
sendMsgStruct.pingPong = false;
sendMsgStruct.msgId = msgId;
rand.nextBytes(sendMsgStruct.bufferMsg);
try {
ObjectOutputStream serializeMobile = new ObjectOutputStream(mobileSocket.getOutputStream());
serializeMobile.writeObject(sendMsgStruct);
serializeMobile.close();
} catch (IOException e1) {
e1.printStackTrace();
return false;
}
服务器反序列化如下:
try {
ObjectInputStream deserializeServer = new ObjectInputStream(clientSocket.getInputStream());
recvMsgStruct = (msgStruct) deserializeServer.readObject();
deserializeServer.close();
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
我在对象被序列化和反序列化的行处遇到异常。