我正在尝试使用javaFX制作多人国际象棋游戏 当player1尝试在服务器中发送游戏请求时,将出现此异常
Exception in thread "Thread-1" java.lang.ExceptionInInitializerError
at java.io.ObjectStreamClass.computeDefaultSUID(ObjectStreamClass.java:1887)
at java.io.ObjectStreamClass.access$100(ObjectStreamClass.java:79)
at java.io.ObjectStreamClass$1.run(ObjectStreamClass.java:263)
at java.io.ObjectStreamClass$1.run(ObjectStreamClass.java:261)
at java.security.AccessController.doPrivileged(Native Method)
at java.io.ObjectStreamClass.getSerialVersionUID(ObjectStreamClass.java:260)
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:682)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1880)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1746)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2037)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1568)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2282)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2206)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2064)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1568)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2282)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2206)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2064)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1568)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2282)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2206)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2064)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1568)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:428)
at ServerSide.ClientHandler.newGameRequest(ClientHandler.java:142)
at ServerSide.ClientHandler.run(ClientHandler.java:62)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater (PlatformImpl.java:273)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:550)
at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:512)
at javafx.scene.control.Control.<clinit>(Control.java:87)
... 34 more
这是代码,异常在game = (Game) ois.readObject();
SimpleUser requestedUser = (SimpleUser) ois.readObject();
game = (Game) ois.readObject();
for (ClientHandler clientHandler : Server.getActiveClients()) {
if (clientHandler.user.getSimpleUser().equals(requestedUser)) {
pairedClientHandler = clientHandler;
pairedClientHandler.getIncomingGameRequests().add(game);
break;
}
}
这是游戏类
package ClientSide.Game;
import General.User.Audience;
import General.User.Player;
import General.User.SimpleUser;
import java.io.Serializable;;
import java.util.ArrayList;
public class Game implements Serializable {
private Board board;
private Player player1;
private Player player2;
private SimpleUser winner;
private SimpleUser loser;
private boolean isDraw;
ArrayList<Audience> audiences;
private ArrayList<Move> moves;
private boolean isRated;
private boolean isPlayer2Accepted;
private int time;
public Board getBoard() {
return board;
}
public Player getPlayer1() {
return player1;
}
public void setPlayer1(Player player1) {
this.player1 = player1;
}
public void setPlayer2(Player player2) {
this.player2 = player2;
}
public Player getPlayer2() {
return player2;
}
public boolean isPlayer2Accepted() {
return isPlayer2Accepted;
}
public void setPlayer2Accepted(boolean player2Accepted) {
isPlayer2Accepted = player2Accepted;
}
public ArrayList<Move> getMoves() {
return moves;
}
public Game() {
}
public Game(Player player1, Player player2, boolean isRated) {
this.player1 = player1;
this.player2 = player2;
this.isRated = isRated;
}
{
board = new Board(this);
moves = new ArrayList<>();
}
public SimpleUser getWinner() {
return winner;
}
public void setWinner(SimpleUser winner) {
this.winner = winner;
}
public SimpleUser getLoser() {
return loser;
}
public void setLoser(SimpleUser loser) {
this.loser = loser;
}
public boolean isDraw() {
return isDraw;
}
public void setDraw(boolean draw) {
isDraw = draw;
}
public int getTime() {
return time;
}
public boolean isRated() {
return isRated;
}
}
答案 0 :(得分:0)
您的可序列化类必须指定一个UUID,并且线程/网络对象流之间的此UUId必须相同,请尝试为代码中的每个可序列化指定一个,然后再尝试:
private static final long serialVersionUID = SOME_LONG_HERE;