Link to home
Start Free TrialLog in
Avatar of tnakamur
tnakamur

asked on

I get an error: Object reference not set to an instance of an object

Hi, I'm getting the error:  
"Object reference not set to an instance of an object"

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Line 589:                        StatusBox.Text = "view is not null";
Line 590:                  
Line 591(this line):                  batchList.DataSource = view;
Line 592://                  batchList.DataBind();
Line 593:            }

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   LoadRunner.WebForm1.displayMenu() in c:\inetpub\wwwroot\loadrunner\webform1.aspx.cs:591
   LoadRunner.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\loadrunner\webform1.aspx.cs:319
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()


The code is as following, where batchList is declared
protected System.Web.UI.WebControls.DataGrid batchList;

==
            private void displayMenu()
            {
                  //read the Xml into DataSet.
                  DataSet ds = new DataSet();
                  ds.ReadXml(Server.MapPath("application.xml"));

                  //Choose the "batchfile"
                  DataView view = ds.Tables["batchfile"].DefaultView;
                  view.Sort = "order" + " DESC";
                  
                  if(view==null)
                        StatusBox.Text = "view is null";
                  else
                        StatusBox.Text = "view is not null";
                  
                  batchList.DataSource = view;
                  batchList.DataBind();
==
This code was working perfectly before, and now it doesn't.  application.xml exists in the appropriate directory (c:\inetput\wwwroot\loadrunner\) and is valid.  I just can't seem to figure out why "batchList.DataSource = view" can be generating an error.

Thank you very much.
Avatar of _TAD_
_TAD_



new need to set you variable to an instance of the object.

That is, get a currently running instance, or create a new one


protected System.Web.UI.WebControls.DataGrid batchList = new DataGrid();

or

protected System.Web.UI.WebControls.DataGrid batchList = DataGrid1; // assuming that you have a datagrid1 on your form


>>new need to set you variable to an instance of the object.    (??)

YOU need to set YOUR .....  holy fat fingers batman!  

Avatar of tnakamur

ASKER

Ahh.  That's gone, but I get the exact same error in the different part of the code:

foreach(DataGridItem item in batchList.Items)
{
                //this line now
      ((CheckBox)item.FindControl("check1")).Enabled = false;
}

Any ideas on this one?
      
Make sure you included in your aspx page:
<asp:DataGrid id="batchList" runat="server">
    ....
</asp:DataGrid>
oops... posted right after you replied

As for your last post... make sure check1 included in your aspx page and/or declared.


Hmmm... this should work.


I'll have to run some tests to see if I can reproduce the error
ASKER CERTIFIED SOLUTION
Avatar of TheAvenger
TheAvenger
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial