Solved

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

Posted on 2004-04-02
7
840 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:tnakamur
7 Comments
 
LVL 22

Expert Comment

by:_TAD_
ID: 10744732


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
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 10744747


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

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

0
 

Author Comment

by:tnakamur
ID: 10744881
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?
      
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 3

Expert Comment

by:gillit
ID: 10744888
Make sure you included in your aspx page:
<asp:DataGrid id="batchList" runat="server">
    ....
</asp:DataGrid>
0
 
LVL 3

Expert Comment

by:gillit
ID: 10744910
oops... posted right after you replied

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

Expert Comment

by:_TAD_
ID: 10746114


Hmmm... this should work.


I'll have to run some tests to see if I can reproduce the error
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 150 total points
ID: 10746636
I think your problems are all with the controls. In the first problem, the null value was probably batchList and not the view. Now you have another problem with a control. Review your HTML code to see if all controls are declared correctly and they are configured to run on the server
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question