I am programming a game in Java (tetris-like) but I got this error when running it :
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: java.awt.image.BufferedImage
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy0.PoolPieces(Unknown Source)
at Fenetre.<init>(Fenetre.java:196)
at Score.lancerNewFenetre(Score.java:103)
So this error happens at the beginning, when I try to retrieve an Array of "Piece" from the server (Class "Partie" (Game)), to then set the pieces and be able to play. The code that makes the error occur is :
try
{
this.unpool = this.ninja.PoolPieces(this.id);
System.out.println(unpool);
this.setBoutons(this.unpool);
System.out.println("boutons set");
}
catch (RemoteException e)
{
e.printStackTrace();
}
It breaks at the first line, where "unpool" is a Piece[], "ninja" is my interface that I set at the beginning of the code, and "PoolPieces" is my method to get a pool of 3 pieces (Piece[]). Here is the code of the method "PoolPieces" :
public Piece[] PoolPieces(Integer id)
{
Integer rang = this.listejoueurs[id].getRang(id);
Integer retour = rang + 1;
this.listejoueurs[id].setRang(retour);
this.leretourpieces = this.piecespartie[rang];
return this.leretourpieces;
}
I have created a class "Joueur" (Player), and every player has a "rang" (rank). So, the avaible pieces are the same for all the players, and they retrieve the pool of pieces according to their progression in the game. The "listejoueurs" is a Joueur[], it is an array containing the different players for the game. The "id" is the identifier to link a client with a player : the first player added is added at place 0 in the array, and the id = 0 is sent to the client. The next player will have id = 1, and so on. "leretourpiece" is my Piece[] that I want to return. It is taken from a Piece[][], created randomly at the beginning of the game. It is an array, of array of 3 Piece. "leretourpiece" gets the pool of piece according to the progression of the player (as explain above).
After looking for that error on internet, I implemented Serializable in barely every class, but nothing changed. The strange thing is also that something the error doesn't show up, and succeeds in getting the pool, maybe once over 10 intents or so, but then, when putting the pieces on the grid I have sme problems, misplacements, etc. (that may be an error in the code that puts the piece on the grid, I am not sure).
So I am quite stuck with that problem and I can't find where it comes from. Thank you very much in advance for the time taken to read this, and eventually help me :)