Solved

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

Posted on 2004-04-02
7
906 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to repeat the data 4 43
Problem to Office 1 68
C# DataTable (in memory) vs SQL Lookups 4 75
asp.net repeater 2 38
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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