我有幾個類。 他們中的一些java - javafx.event.EventHandler是一個接口,並且JAXB無法處理接口
類遊戲
@XmlRootElement(name = "game")
public class Game {
private int scores = 0;
private Field field;
...
@XmlElement
public int getScores() {
return scores;
}
public void setScores(int scores) {
this.scores = scores;
}
@XmlElement
public Field getField() {
return field;
}
public void setField(Field field) {
this.field = field;
}
@XmlElement(name="NewShape")
public ArrayList<Shapes> getNewShapes() {
return newShapes;
}
public void setNewShapes(ArrayList<Shapes> newShapes) {
this.newShapes = newShapes;
}
...
類形狀
@XmlSeeAlso({RectangleVertic.class, RectangleHoriz.class, Square.class, Angle.class})
public abstract class Shapes {
private double widthOfSquare, widthBetweenSquares, totalWidth, totalHeight;
private int countOfSquaresInWidth, countOfSquaresInHeight;
private ArrayList<Rectangle> rectangles= new ArrayList();
private Group group;
public Shapes(){
}
public Shapes(double widthOfSquare, double widthBetweenSquares){
this.widthOfSquare=widthOfSquare;
this.widthBetweenSquares=widthBetweenSquares;
}
@XmlElement(type = Group.class)
public Group getGroup() {
return group;
}
public void setGroup(Group group){
this.group=group;
}
@XmlTransient
public double getWidthBetweenSquares() {
return widthBetweenSquares;
}
@XmlTransient
public int getCountOfSquaresInWidth() {
return countOfSquaresInWidth;
}
@XmlTransient
public int getCountOfSquaresInHeight() {
return countOfSquaresInHeight;
}
@XmlTransient
public ArrayList<Rectangle> getRectangles() {
return rectangles;
}
public void setRectangles(ArrayList<Rectangle> rectangles) {
this.rectangles = rectangles;
}
@XmlTransient
public double getTotalWidth() {
return totalWidth;
}
@XmlTransient
public double getTotalHeight() {
return totalHeight;
}
@XmlTransient
public double getWidthOfSquare() {
return widthOfSquare;
}
...
public abstract boolean putRectOnField(int startI, int startJ, ArrayList<Object[]> horizLinesOfSquare, ArrayList<Object[]> verticLinesOfSquare);
public abstract boolean checkPutRectOnField(int startI, int startJ, ArrayList<Object[]> horizLinesOfSquare, ArrayList<Object[]> verticLinesOfSquare);
public abstract int countOfShape();
}
班編組
public class JaxbParser implements Parser {
@Override
public Object getObject(File file, Class c) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(c);
Unmarshaller unmarshaller = context.createUnmarshaller();
Object object = unmarshaller.unmarshal(file);
return object;
}
@Override
public void saveObject(File file, Object o) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(o.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(o,file);
}
}
當我嘗試元帥,我得到以下錯誤:
javafx.event.EventDispatcher is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at javafx.event.EventDispatcher at public final javafx.event.EventDispatcher javafx.scene.Node.getEventDispatcher() at javafx.scene.Node at javafx.scene.shape.Shape at javafx.scene.shape.Rectangle at private java.util.ArrayList graphic.Shapes.rectangles at graphic.Shapes at private java.util.ArrayList game.Game.newShapes at game.Game
javafx.scene.input.InputMethodRequests is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at javafx.scene.input.InputMethodRequests at public final javafx.scene.input.InputMethodRequests javafx.scene.Node.getInputMethodRequests() at javafx.scene.Node at javafx.scene.shape.Shape at javafx.scene.shape.Rectangle at private java.util.ArrayList graphic.Shapes.rectangles at graphic.Shapes at private java.util.ArrayList game.Game.newShapes at game.Game
javafx.event.EventHandler is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at javafx.event.EventHandler at public final javafx.event.EventHandler javafx.scene.Node.getOnContextMenuRequested() at javafx.scene.Node at javafx.scene.shape.Shape at javafx.scene.shape.Rectangle at private java.util.ArrayList graphic.Shapes.rectangles at graphic.Shapes at private java.util.ArrayList game.Game.newShapes at game.Game
如果從類形狀編組刪除元素組羣,也沒有任何錯誤。 我錯過了什麼? 謝謝。
非常感謝。如果不是爲了你,我會一直試着去理解爲什麼會發生這種情況。 –
不客氣;) –