我正在使用 Serializable 进行数据传输。以下是我在 Serializable 中的课堂暗示。
public class UserAction implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
public int userID;
public transient Path path;
public transient Paint paint;
public UserAction(){
path = new Path();
paint = new Paint();
}
public UserAction(int ID, Path path, Paint paint){
setUserID(ID);
setPath(path);
setPaint(paint);
}
public void setUserID(int ID){
this.userID = ID;
}
public void setPath(Path path){
this.path.set(path);
}
public void setPaint(Paint paint){
this.paint.set(paint);
}
}
输出流是这样的:
client = new Socket("localhost", 54321);
ObjectOutputStream out = new ObjectOutputStream(client.getOutputStream());
out.writeObject(action);
out.close();
client.close();
输入流是:
ObjectInputStream in = new ObjectInputStream(client.getInputStream());
rec_action = (UserAction) in.readObject();
in.close();
但是当我使用从输入流中得到的 rec_action 时。rec_action 不是 Null,但它的成员路径和绘制都是 NULL!获取java.lang.NullPointerException。