Bonjour à tous je suis en train de faire une petite application qui envoie un objet personne du client au serveur mais j'ai une erreur "java.lang.ClassNotFoundException: org.client.object.Personne"
voici le serveur
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package org.kodejava.example.net;
 
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.ClassNotFoundException;
import java.lang.Runnable;
import java.lang.Thread;
import java.net.ServerSocket;
import java.net.Socket;
 
import org.server.object.Personne;
 
public class Server4 {
    private ServerSocket server;
    private int port = 7777;
 
    public Server4() {
        try {
            server = new ServerSocket(port);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    public static void main(String[] args) {
        Server4 example = new Server4();
        example.handleConnection();
    }
 
    public void handleConnection() {
        System.out.println("Waiting for client message...");
 
        //
        // The server do a loop here to accept all connection initiated by the
        // client application.
        //
        while (true) {
            try {
                Socket socket = server.accept();
                new ConnectionHandler(socket);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
class ConnectionHandler implements Runnable {
    private Socket socket;
 
    public ConnectionHandler(Socket socket) {
        this.socket = socket;
 
        Thread t = new Thread(this);
        t.start();
    }
 
    public void run() {
        try
        {
            //
            // Read a message sent by client application
            //
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
          //  String message = (String) ois.readObject();
            Personne p=(Personne) ois.readObject();;
            System.out.println("Message Received: " + p.getNom());
 
            //
            // Send a response information to the client application
            //
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
            oos.writeObject("Hi...");
 
            ois.close();
            oos.close();
            socket.close();
 
            System.out.println("Waiting for client message...");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
le client
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
41
42
43
44
45
package org.kodejava.example.net;
 
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.ClassNotFoundException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
 
import org.client.object.Personne;
 
public class Client4 {
    public static void main(String[] args) {
        try {
            //
            // Create a connection to the server socket on the server application
            //
          //  InetAddress host = InetAddress.getLocalHost();
            Socket socket = new Socket("127.0.0.1", 7777);
 
            //
            // Send a message to the client application
            //
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
            oos.writeObject(new Personne(10,"Houx","Zart"));
 
            //
            // Read and display the response message sent by server application
            //
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            String message = (String) ois.readObject();
            System.out.println("Message: " + message);
 
            ois.close();
            oos.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
et la classe personne
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
 * 
 */
package org.client.object;
 
import java.io.Serializable;
 
/**
 * @author lamine
 *
 */
public class Personne implements Serializable{
	private int age;
 
    private String nom;
 
    private String prenom;
 
    public Personne() {
    }
 
    public Personne(int age,String nom, String prenom) {
           this.age = age;
           this.nom = nom;
           this.prenom = prenom;
    }
 
 
    /**
     * Gets the age value for this Personne.
     * 
     * @return age
     */
    public int getAge() {
        return age;
    }
 
 
    /**
     * Sets the age value for this Personne.
     * 
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }
 
 
    /**
     * Gets the nom value for this Personne.
     * 
     * @return nom
     */
    public java.lang.String getNom() {
        return nom;
    }
 
 
    /**
     * Sets the nom value for this Personne.
     * 
     * @param nom
     */
    public void setNom(java.lang.String nom) {
        this.nom = nom;
    }
 
 
    /**
     * Gets the prenom value for this Personne.
     * 
     * @return prenom
     */
    public java.lang.String getPrenom() {
        return prenom;
    }
 
 
    /**
     * Sets the prenom value for this Personne.
     * 
     * @param prenom
     */
    public void setPrenom(java.lang.String prenom) {
        this.prenom = prenom;
    }
 
}
Merci d'avance