bonjour
j'ai cette classe :
et j'ai ce main:Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Personne { String name; int age; public Personne(String name,int age) { this.name=name; this.age=age; } public void enregistrePers() throws FileNotFoundException, IOException { ObjectOutputStream sortie = new ObjectOutputStream (new FileOutputStream("recept")); sortie.writeObject(this); sortie.close(); } }
après la compilation j'ai obtenu cet erreur:Code:
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 import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { /** * @param args */ public static void main(String[] args) { Personne pers=new Personne("Omar",23); try { pers.enregistrePers(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
qui peut m'aider SVP et merci
l'erreur est:
Citation:
java.io.NotSerializableException: Personne
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at Main.main(Main.java:18)