Bonjour,
Je cherche � faire un syst�me d'IA pour un jeu. Ce dernier marche tr�s bien mais je cherche � �diter mes diff�rentes strat�gies de fa�ons simple. J'ai donc choisi de cr�er un fichier xml contenant (pour commencer) une strat�gie.
Strat�gie est la classe m�re. Les classes actions et condition h�ritent de cette derni�re. Il y a d'autres classes plus sp�cifique qui h�ritent sois d'Action, soient de Condition (respectivement, comme Avancer et PeutAvancer).
J'ai fais des recherches et Xstream m'a l'air d'�tre tr�s bien pour faire ce que je veux faire : parser le fichier xml est cr�er des strat�gies en fonction de.
Voici un exemple de mon fichier xml :
Ma classe XmlParser :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10 <?xml version="1.0" encoding="UTF-8"?> <AssezEnergie> <seuil>25</seuil> <PeutAvancer> <Avancer></Avancer> <RotationDroite></RotationDroite> </PeutAvancer> <NeRienFaire></NeRienFaire> </AssezEnergie>
A l�ex�cution j'ai l'erreur suivante :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 package modele; import java.io.FileReader; import java.util.concurrent.locks.Condition; import java.io.FileNotFoundException; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; import strategie.Strategie; import strategie.action.Avancer; import strategie.action.NeRienFaire; import strategie.action.RotationDroite; import strategie.condition.AssezEnergie; import strategie.condition.PeutAvancer; public class XmlParser { public static void main(String[] args) throws FileNotFoundException { FileReader reader = new FileReader("C:/Users/tomhoo/Documents/S5/genie_logiciel/projet/ambroise-gouedard-jeanbaptiste-perais/xml/simple.xml"); XStream xstream = new XStream(); xstream.alias("Strategie", Strategie.class); xstream.alias("AssezEnergie", AssezEnergie.class); xstream.alias("PeutAvancer", PeutAvancer.class); xstream.alias("Avancer", Avancer.class); xstream.alias("RotationDroite", RotationDroite.class); xstream.alias("NeRienFaire", NeRienFaire.class); Strategie test = (Strategie) xstream.fromXML(reader); } }
Quelqu'un saurait-il ce qui cloche ?
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 Exception in thread "main" com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field strategie.condition.AssezEnergie.PeutAvancer ---- Debugging information ---- field : PeutAvancer class : strategie.condition.AssezEnergie required-type : strategie.condition.AssezEnergie converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter path : /AssezEnergie/PeutAvancer line number : 4 version : 1.4.8 ------------------------------- at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.handleUnknownField(AbstractReflectionConverter.java:501) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:357) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:263) at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134) at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1206) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1190) at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1061) at modele.XmlParser.main(XmlParser.java:31)
Partager