Hi,
ich hab versucht manuell Klassen aus einer .xsd zu erstellen weil mein xjc tool nicht funktioniert hab schon alles versucht selbst neu installation es hängt sich immer auf.
Aber egal ich brauche in diesem Fall eh nur eine .xsd umsetzten von daher hier mal was ich gemacht habe und die Fehlermeldung:
[XML]
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="map">
<xs:complexType>
<xs:sequence>
<xs:element name="country" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="x" type="xs:integer" />
<xs:element name="y" type="xs:integer" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
[/XML]
bsp.:
[XML]
<?xml version="1.0" encoding="UTF-8"?>
<map name="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="field.xsd">
<country>
<name>test1</name>
<x>110</x>
<y>20</y>
</country>
<country>
<name>test2</name>
<x>200</x>
<y>30</y>
</country>
</map>
[/XML]
Dazu habe ich folgende Klassen erstellt:
Die Fehlermeldung lautet wie folgt:
javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "countries"
this problem is related to the following location:
at public java.util.List game.view.gui.controller.jaxb.Map.getCountries()
...
Welche "Annotation" ist falsch? Bzw. sollte geändert werden? Oder liegt der Fehler eigentlich woanders?
Danke schonmal für die Hilfe.
MfG
baxbear
ich hab versucht manuell Klassen aus einer .xsd zu erstellen weil mein xjc tool nicht funktioniert hab schon alles versucht selbst neu installation es hängt sich immer auf.
Aber egal ich brauche in diesem Fall eh nur eine .xsd umsetzten von daher hier mal was ich gemacht habe und die Fehlermeldung:
[XML]
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="map">
<xs:complexType>
<xs:sequence>
<xs:element name="country" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="x" type="xs:integer" />
<xs:element name="y" type="xs:integer" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
[/XML]
bsp.:
[XML]
<?xml version="1.0" encoding="UTF-8"?>
<map name="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="field.xsd">
<country>
<name>test1</name>
<x>110</x>
<y>20</y>
</country>
<country>
<name>test2</name>
<x>200</x>
<y>30</y>
</country>
</map>
[/XML]
Dazu habe ich folgende Klassen erstellt:
Java:
package game.view.gui;
import javax.xml.bind.annotation.XmlRegistry;
@XmlRegistry
public class ObjectFactory {
public ObjectFactory() {
}
public Map createMap() {
return new Map();
}
}
Java:
package game.view.gui;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement( name = "map" )
public class Map {
@XmlAttribute
private String name;
private List<Country> countries = new ArrayList<Country>();
@XmlElement(name = "country")
public List<Country> getCountries() {
return countries;
}
public void setCountries( List<Country> countries ) {
this.countries = countries;
}
}
Java:
package game.view.gui;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "country")
public class Country {
@XmlElement(required = true)
private String name;
@XmlElement(required = true)
private int x;
@XmlElement(required = true)
private int y;
public String getName() {
return name;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
Die Fehlermeldung lautet wie folgt:
javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "countries"
this problem is related to the following location:
at public java.util.List game.view.gui.controller.jaxb.Map.getCountries()
...
Welche "Annotation" ist falsch? Bzw. sollte geändert werden? Oder liegt der Fehler eigentlich woanders?
Danke schonmal für die Hilfe.
MfG
baxbear
Zuletzt bearbeitet: