对JavaFX对象使用GSON
我正在使用GSON保存/加载 我的一个对象拥有一个对JavaFX对象使用GSON,java,javafx,gson,Java,Javafx,Gson,我正在使用GSON保存/加载 我的一个对象拥有一个标签和一个图像视图(JavaFX对象) 这给我带来了一个溢出错误 JavaFX控制器类 public void saveButtonAction(Event e) throws IOException { Gson output = new Gson(); output.toJson(tile); //tile is an instance of Tile } 瓷砖类 //Tile
标签
和一个图像视图
(JavaFX对象)
这给我带来了一个溢出错误
JavaFX控制器类
public void saveButtonAction(Event e) throws IOException {
Gson output = new Gson();
output.toJson(tile); //tile is an instance of Tile
}
瓷砖类
//Tile Class
public class Tile{
private String type;
private boolean hasMule;
private Player owner;
private ImageView image;
private String production;
private Label label;
/** tile constructor
* @param image image
* @param label label
*/
public Tile(ImageView image, Label label) {
this.type = null;
this.hasMule = false;
this.owner = null;
this.image = image;
this.production = null;
this.label = label;
}
/** set type of the tile
* @param type type of the tile to be set
*/
public void setType(String type) {
if (type != null) {
this.type = type;
}
}
/** set if tile has mule or not
* @param hasMule boolean true if tile has mule or fasle if not
*/
public void setHasMule(boolean hasMule) {
this.hasMule = hasMule;
}
/** set owner to the tile
* @param owner to be set as onwer for the tile
*/
public void setOwner(Player owner) {
this.owner = owner;
}
/** set the image to the tile
* @param image to be set for the tile
*/
public void setImage(ImageView image) {
this.image = image;
}
/** set production for the tile
* @param production for the tile
*/
public void setProduction(String production) {
this.production = production;
}
/** get type of the tile
* @return type of the tile
*/
public String getType() {
return type;
}
/** get if the tile has mule or not
* @return boolean false if tile does not have mule, true otherwise
*/
public boolean getHasMule() {
return hasMule;
}
/** get owner of the tile
* @return owner of the tile
*/
public Player getOwner() {
return owner;
}
/** get image
* @return image of the tile
*/
public ImageView getImage() {
return image;
}
/** get production
* @return production of the tile
*/
public String getProduction() {
return production;
}
}
这是我收到的错误消息
我能问一下为什么会这样吗
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
... 45 more
Caused by: java.lang.StackOverflowError
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:378)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:383)
您需要发布导致此错误的代码。