Bonjour,

J'ai deux erreurs d'instanciation, mais étant débutante en Java, je n'arrive pas à régler mon problème toute seule.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
Exception in thread "main" java.lang.NullPointerException
    at ServeurEcho.listerFichiers(ServeurEcho.java:37)
    at ServeurEcho.main(ServeurEcho.java:57)
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
import java.io.*;
import java.net.*;
 
public class ServeurEcho
{
    /**
     * afficherFichiers :
     * On test si le fichier est un fichier, si c'est le cas on affiche la taill en octet du fichier.
     * Si ce n'est pas un fichier, on test alors si c'est un répertoire, si c'est le cas on affiche son nom avec un "/" de séparation pour bien le différencier des fichiers.
     * Si ce n'est pas non plus un répertoire, on affiche donc que l'objet est de type inconnu
     */
    static public void afficherFichiers(File f) {
        if (f.isFile()) {
            System.out.println(f.getName()+" Taille: "+f.length()+" octets");
            return;
        }
        if (f.isDirectory()) {
            System.out.println(f.getName()+File.separator);
            return;
        }
        System.out.println(f.getName()+" : type inconnu");
    }
 
    /**
     * listerFichiers :
     * Création d'un objet de type File.
     * On affiche le chemin du répertoire courant.
     * On place les fichiers dans un tableau, ces fichiers seront ensuite afficher à chaque incrémentation de la variable i (bornée entre 1 et le nombres de fichiers présents dans le répertoire.
     */
    static public void listerFichiers(String name) {
        File f = new File(name);
        int i;
        System.out.println("Répertoire: "+f.getAbsolutePath());
        File []files = f.listFiles();
        for (i=0; i<files.length; i++) afficherFichiers(files[i]);
    }
 
    final static int taille = 1024;
    final static byte buffer[] = new byte[taille];
 
    public static void main(String argv[]) throws Exception
    {
        InetAddress client = InetAddress.getByName(argv[0]);
 
        String []names;
        int i;
 
        if (argv.length==0) {
            names = new String[1];
            names[0] = ".";
        }
        else {
            names = argv;
        }
        for (i=0; i<names.length; i++) listerFichiers(names[i]);
 
        int length = argv[1].length();
        byte buffer[] = argv[1].getBytes();
        DatagramPacket dataSent = new DatagramPacket(buffer,length,client,ClientEcho.port);
        DatagramSocket socket = new DatagramSocket();
 
        socket.send(dataSent);
 
        DatagramPacket dataRecieved = new DatagramPacket(new byte[length],length);
        socket.receive(dataRecieved);
        //System.out.println("Data recieved : " + new String(dataRecieved.getData()));
        System.out.println("From : " + dataRecieved.getAddress() + ":" + dataRecieved.getPort());
    }
}
Quelqu'un saurait-il me dire d'où vient mon problème ?

Merci d'avance !