Hallo
j ai vollu faire un petit exemple pour tester l enregistrement dan un fichier xml.
je veux sauvegarder les Attribut de deux classe de maniere Herarvchie dans une Fichier XML. voila mon code:

la premiere classe Konfuguration:

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
import java.util.ArrayList;
import java.util.List;
 
 
public class Konfiguration {
	private String name = "";
 
	private List<Project> project = new ArrayList<Project>();
	public Konfiguration() {
		name = "(Standardkonfiguration)";
	}
 
 
	public void addProject(Project projectNeu) {
		this.project.add(projectNeu);
	}
	/**
         * @return
         */
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
 
	public void setProjekt(List<Project> Project){
		this.project= Project;
	}
 
	public List<Project> getProject(){
		return project;
	}
 
 
}
la deuxiene classe roject

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
import java.util.ArrayList;
import java.util.List;
 
public class Project {
 
 
	private String projectName;
 
	public Project() {
 
	}
 
 
 
	public String getProjectName(){
		return this.projectName;
	}
 
	public void setProjectName(String projectName){
		this.projectName = projectName;
	}	
 
 
 
}
et ma klasse class KonfigurationReader: qui ecrire dans le fichier xml

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
38
39
40
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
 
public class KonfigurationReader {
 
 
 
	public static void serializeTree(Konfiguration konfiguration, String filename) throws IOException {
	        FileOutputStream fos = new FileOutputStream(filename);
	        BufferedOutputStream bos = new BufferedOutputStream(fos);
	        XMLEncoder xmlEncoder = new XMLEncoder(bos);
	        xmlEncoder.writeObject(konfiguration);
	        xmlEncoder.close();
	}
}
 
et enfin la class main:
 
public class Main {
 
/**
         * @param args
         */
public static void main(String[] args) throws Exception {
 
	Konfiguration testKonfiguration = new Konfiguration();
 
	Project testProject= new Project();
 
	testKonfiguration.addProject(testProject);
	KonfigurationReader.serializeTree(testKonfiguration, "C:\\Tmp\\LPR-Konfiguration.xml");
 
}
 
}
je ne sais pas ou est la problem.
pour les deux classe j ai ajouter un constructeur par défaut (sans paramètre)
et Les attributs de mes classe sont accessibles via des accesseurs/modifieurs

j espere que quelquin peut m aider, j ai besoin de connetre le problem le plut tot possible

merci becoup en avance