Solved

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

Posted on 2004-04-02
7
813 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now