Bonsoir,

J'ai actuellement un petit problème sur un debut de programme concernant une arrayList je pense. Je travaille sous éclipse.

Voici le code
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
 import java.util.ArrayList;
 
 
public class Personne {
 
	private int id;
	private String nom;
	private String prenom;
	private int age;
	private String adresse;
	private int codeP;
	private String commune;
	private ArrayList lesObjetsLoues;
 
 
	public Personne(int id, String nom, String prenom, int age, String adresse,
			int codeP, String commune) {
		super();
		this.id = id;
		this.nom = nom;
		this.prenom = prenom;
		this.age = age;
		this.adresse = adresse;
		this.codeP = codeP;
		this.commune = commune;
	}
 
 
	public int getId() {
		return id;
	}
 
	public int getAge() {
		return age;
	}
 
	public void setAge(int age) {
		this.age = age;
	}
 
	public String getAdresse() {
		return adresse;
	}
 
	public void setAdresse(String adresse) {
		this.adresse = adresse;
	}
 
	public int getCodeP() {
		return codeP;
	}
 
	public void setCodeP(int codeP) {
		this.codeP = codeP;
	}
 
	public String getNom() {
		return nom;
	}
 
	public String getPrenom() {
		return prenom;
	}
 
	public String getCommune() {
		return commune;
	}
 
	public void addObjet(Objet unObjet){
		lesObjetsLoues.add(unObjet);
 
	}
 
	public Objet getObjet(int i){
		return (Objet)lesObjetsLoues.get(i);
	}
 
 
}
 
 
 
import java.util.ArrayList;
 
 
public class Objet {
 
	private int identifiant;
	private String libelle;
	private int prix;
	private ArrayList lesPersonnesLouantes;
 
 
 
 
	public Objet(int identifiant, String libelle, int prix) {
		super();
		this.identifiant = identifiant;
		this.libelle = libelle;
		this.prix = prix;
	}
 
 
	public int getPrix() {
		return prix;
	}
	public void setPrix(int prix) {
		this.prix = prix;
	}
	public int getIdentifiant() {
		return identifiant;
	}
	public String getLibelle() {
		return libelle;
	}
 
	public void addPersonne(Personne unePersonne){
		lesPersonnesLouantes.add(unePersonne);
 
	}
 
}
 
 
 
public class Louer {
 
private String date;
 
 
public Louer( String date, Personne unePersonne, Objet unObjet) {
	super();
	this.date = date;
	unePersonne.addObjet(unObjet);
	unObjet.addPersonne(unePersonne);
}
 
}
 
 
public class Main {
 
	/**
         * @param args
         */
	public static void main(String[] args) {
		Objet unObjet = new Objet(1,"Tintin",2);
		Personne unePersonne = new Personne(1,"Dupont","Jean",15,"pigeonniere",44350,"Nantes");
		Louer uneLocation = new Louer("15/05/2009",unePersonne,unObjet);
		System.out.println(unePersonne.getObjet(0).getLibelle());
 
	}
 
}

Voici donc mon code. Le principe est qu'une personne puisse louer un objet. Mon message d'erreur est le suivant :

Exception in thread "main" java.lang.NullPointerException
at Personne.addObjet(Personne.java:70)
at Louer.<init>(Louer.java:10)
at Main.main(Main.java:10)


Je ne comprends pas. Merci de votre futur aide.
@++