I'm trying to deep copy an array of my custom object "Space", which extends javafx Pane.
I've tried using Kryo libraries, and implementing clonable. I could use work arounds that don't actually deep copy, but that will make my code 100x more janky.
Currently I have the class Space:
public class Space extends Pane {
private boolean available = true;
private boolean light;
private int x;
private int y;
private Peice peice;
private Label peiceImage;
private Rectangle border;
public Space() {}
public Space(int x, int y, boolean light) {
border = new Rectangle(80,80);
if (!light) {
border.setFill(Color.DARKGREEN);
border.setStroke(Color.DARKGREEN);
} else {
border.setFill(null);
border.setStroke(null);
}
peiceImage = new Label();
peiceImage.setTranslateX(16);
peiceImage.setTranslateY(16);
getChildren().addAll(border,peiceImage);
this.x = x;
this.y = y;
this.peice = null;
this.light = light;
}
//other unimportant methods.
}
I then try to copy in another file:
public Space[][] copyBoard(Space[][] thisBoard) {
Kryo kryo = new Kryo();
Space[][] copy = new Space[8][8];
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
Space thisSpace = thisBoard[x][y];
try {
kryo.setRegistrationRequired(false);
copy[x][y] = kryo.copy(thisSpace); //TODO This causes exception, dosent work
} catch (Exception e) {
System.out.println(e);
}
}
}
return copy;
}
Trying to use the kryo library I get this error:
com.esotericsoftware.kryo.KryoException: Class cannot be created (missing no-arg constructor): javafx.scene.layout.Region$3
But I'm not in any way commited to using kryo.
Thanks.