Probléme : Object reference not set to an instance of an object

Résolu
ami7 Messages postés 99 Date d'inscription dimanche 8 août 2010 Statut Membre Dernière intervention 29 juin 2011 - 30 mars 2011 à 01:35
ami7 Messages postés 99 Date d'inscription dimanche 8 août 2010 Statut Membre Dernière intervention 29 juin 2011 - 30 mars 2011 à 11:39
bonjour

j'ai message d'erreur suivant : Object reference not set to an instance of an object
et indique un trait jaune au niveau de la méthode " dessiner_Sommet(Sommet s)"
mon code c'est :

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;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public List<Sommet> les_Sommets = new List<Sommet>();
public List Les_Aretes = new List();
public Graphics g;
public Sommet s = new Sommet();
public Graphe G = new Graphe();
public Arete A = new Arete();
private int rayon_cercle = 18;
public Form1()
{
InitializeComponent();
les_Sommets = G.les_Som;
}

//retrouver un Sommet par son nom
public Sommet trouver_Sommet(string nom)
{
foreach (Sommet s in les_Sommets)
if (s.nom == nom)
return s;
return null;
}

private void button1_Click(object sender, EventArgs e)
{

Sommet nouveau = new Sommet((int)numericUpDown1.Value, (int)numericUpDown2.Value, textBox1.Text);
if (ajouter_Sommet(nouveau))
{

reafficher();
}
}

private void reafficher()
{


afficher_les_Sommets();
g.Flush();
}

private void afficher_les_Sommets()
{
foreach (Sommet s in les_Sommets)
{
dessiner_Sommet(s);
}
}

private void dessiner_Sommet(Sommet s)
{


g.FillEllipse(new SolidBrush(Color.Blue), s.x, s.y, rayon_cercle, rayon_cercle);

g.DrawString(s.nom, new Font("Microsoft Sans Serif", 15), new SolidBrush(Color.Black), new PointF((float)s.x + rayon_cercle, (float)s.y));
}

private bool ajouter_Sommet(Sommet nouvelle)
{
if (nouvelle.nom != string.Empty)
{
foreach (Sommet s in les_Sommets)
{
if ((s.x nouvelle.x && s.y nouvelle.y) || s.nom == nouvelle.nom)
{
MessageBox.Show("Nouveau Sommet Invalide\n Verifiez Que le Nom ou les Coordonnees n'existent pas deja", "Du calme", MessageBoxButtons.OK);
return false;

}

}
les_Sommets.Add(nouvelle);
}
else
{
MessageBox.Show("Vous devez entrer le Nom du Sommet", "Du calme", MessageBoxButtons.OK);
return false;
}
return true;
}
}
}

3 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
30 mars 2011 à 09:23
ou assignes tu g ?

Renfield - Admin CodeS-SourceS - MVP Visual Basic & Spécialiste des RegExp
3
Rejoignez-nous