Bonjour, j'ai une erreur à la ligne : MessageBox.Show("Votre solde actuel est" + list_user[i].Compte_user.Solde_actuelle);
qui dit : Object reference not set to an instance of an object

Classe Compte
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
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
 
namespace Ex7
{
    [Serializable]
 
    class Compte
    {
 
        private int no_compte;
        private float solde_actuelle = 50f;
        private float solde_max;
        private float solde_min;
 
        public Compte() { }
 
        public Compte(int c_no_compte, float c_solde_actuelle, float c_solde_max, float c_solde_min)
        {
            this.no_compte = c_no_compte;
            this.solde_actuelle = c_solde_actuelle;
            this.solde_max = c_solde_max;
            this.solde_min = c_solde_min;
        }
 
        public int No_compte
        {
            get { return no_compte; }
            set { no_compte = value; }
        }
 
        public float Solde_actuelle
        {
            get { return solde_actuelle; }
            set { solde_actuelle = value; }
        }
 
        public float Solde_max
        {
            get { return solde_max; }
            set { solde_max = value; }
        }
 
        public float Solde_min
        {
            get { return solde_min; }
            set { solde_min = value; }
        }
    }
}
Classe Utilisateurs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
//sérialisation
 
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
 
namespace Ex7
{
    [Serializable]
    class Utilisateurs
    {
        // attributs privées
 
        private string nom;
        private string prenom;
        private string pass;
        private string login;
        private int no_compte;
        private Compte compte_user = new Compte();
 
        public Utilisateurs(string c_nom, string c_prenom, string c_pass, string c_login, int c_no_compte)
        {
            nom = c_nom;
            prenom = c_prenom;
            pass = c_pass;
            login = c_login;
            no_compte = Convert.ToInt32(c_no_compte); 
 
        }
 
        // attributs publiques
 
        public string Prenom
        {
            get { return prenom; }
            set { prenom = value; }
        }
 
        public string Pass
        {
            get { return pass; }
            set { pass = value; }
        }
 
        public int No_compte
        {
            get { return no_compte; }
            set { no_compte = value; }
        }       
 
        public string Nom
        {
            get { return nom; }
            set { nom = value; }
        }
 
        public string Login
        {
            get { return login; }
            set { login = value; }
        }
 
        public Compte Compte_user
        {
            get { return compte_user; }
            set { compte_user = value; }
        }
    }
}
Form1
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
 
namespace Ex7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
 
        private void btConnexion_Click(object sender, EventArgs e)
        {
 
            IFormatter formatter = new BinaryFormatter();
            Stream stream = new FileStream("File.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
            List<Utilisateurs> list_user = (List<Utilisateurs>)formatter.Deserialize(stream);
            stream.Close();
            for (int i = 0; i < list_user.Count; i++) 
            {
                if (tbLogin.Text == list_user[i].Login && tbPassword.Text == list_user[i].Pass)
                {
                    MessageBox.Show("Vous etes connecté");
                    MessageBox.Show("votre numéro de compte est" + list_user[i].No_compte);
                    MessageBox.Show("Votre solde actuel est" + list_user[i].Compte_user.Solde_actuelle);
                    Banque bq = new Banque();
                    bq.Show();
                }
            }
 
 
 
        }
 
        private void btNoveauUtilisateur_Click(object sender, EventArgs e)
        {
            FormNoveauUtilisateur fnu = new FormNoveauUtilisateur();
            fnu.Show();
        }
 
 
    }
}