Erreur System.NullReferenceException: La référence d'objet n'est pas définie à u

cs_aminetazi Messages postés 1 Date d'inscription dimanche 14 mars 2010 Statut Membre Dernière intervention 19 juillet 2012 - 19 juil. 2012 à 17:04
cs_jopop Messages postés 1540 Date d'inscription lundi 26 mai 2003 Statut Membre Dernière intervention 1 août 2013 - 20 juil. 2012 à 08:41
Coucou les ami(e)s
je devellope un site web intranet qui automatise la gestion des workflow des demandes de centres.
j'ai ajouter une page aspx qui contient un gridview avec deux button "Accepter" et "Rejeter";quand je click sur Accepter,un msg d'erreur qui apparaitre "System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet." sur la ligne if (centreService.Acceptation(nLigneDemandeCentres))
voila le code de la page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime;
using System.Workflow.Runtime.Hosting;
using Workflows;
using System.Workflow.Runtime;
using Database;


namespace WebApplication
{
public partial class TraitementCentres : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
Int32 indx = Convert.ToInt32(e.CommandArgument);

Guid nLigneDemandeCentres = new Guid(GridView1.Rows[indx].Cells[0].Text);

Label1.Text = GridView1.Rows[indx].Cells[0].Text;


WorkflowRuntime runtimeC = (WorkflowRuntime)Application["WorkflowRuntime"];
ManualWorkflowSchedulerService scheduler =
(ManualWorkflowSchedulerService)runtimeC.GetService(typeof(ManualWorkflowSchedulerService));

CentreServices centreService = (CentreServices)runtimeC.GetService();

switch (e.CommandName)
{
case "Accepter":
if (centreService.Acceptation(nLigneDemandeCentres))
{
scheduler.RunWorkflow(nLigneDemandeCentres);
}
else
Label1.Text = "probleme Accepter";
break;
case "Rejeter":
if (centreService.Rejet(nLigneDemandeCentres))
{
scheduler.RunWorkflow(nLigneDemandeCentres);
}
else
Label1.Text = "probleme Rejeter";
break;

}

}
protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{

}

}
}

1 réponse

cs_jopop Messages postés 1540 Date d'inscription lundi 26 mai 2003 Statut Membre Dernière intervention 1 août 2013 12
20 juil. 2012 à 08:41
Salut,

ton erreur vient du fait que ta variable centreService n'est pas initialisée (elle est null), et donc tu ne peux pas faire appel à ses méthodes et attributs.
As-tu le même souci sur ta fonctionnalité "Rejeter" ?
0
Rejoignez-nous