Я пытаюсь отправить следующее, но я получаю следующую ошибку ниже. TableUser реализует сериализуемый, но кажется, что проблема в FXCollections, но я не знаю, как это сделать.java.io.NotSerializableException Проблема
Это класс TableUser.
package application;
import java.io.Serializable;
public class TableUser implements Serializable{
private static final long serialVersionUID = 1L;
private String username = "";
public TableUser(String name) {
this.username = name;
}
public String getUsername(){
return username;
}
public void setUsername(String user){
username = user;
}
}
//NOT apart of TableUser - This is the code that isn't working
private static ObservableList<TableUser> clientList = FXCollections.observableArrayList();
Object[] data = new Object[2];
data[0] = "CLIENTS";
data[1] = clientList;
for(int i = 0; i < clients.size(); i++){
clients.get(i).sendData(data);
}
//I don't know if this helps but here is the sendData method
protected void sendData(Object[] data){
try {
oos.writeObject(data); //ServerMultiClient.java:286
oos.reset();
} catch (IOException e) {
e.printStackTrace();
}
}
//This is from the Client application that is also part of the issue
if((fromServer = (Object[]) ois.readObject()) != null){ //Controller.java:109
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.sun.javafx.collections.ObservableListWrapper
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at application.ChatRoomController$2.run(Controller.java:109)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.NotSerializableException: com.sun.javafx.collections.ObservableListWrapper
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeArray(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at application.ServerMultiClient.sendData(ServerMultiClient.java:286)
at application.ServerMultiClient.run(ServerMultiClient.java:236)
Только в случае, если вы еще не пробовали , xmlEncoder работает с наблюдаемыми списками. Я кодирую их в zip-файлы для размера и, возможно, скорости. Возможно, вам придется изменить приватный статический, я не помню. – brian