1

Not a duplicate asking for debugging help, not what a Null Reference exception is.

My program is used to loop through an excel file and grab values.

In this section:

foreach (Data data in DataL)
     {
         if (data.Columns.Contains(GetColumnName(h.CellReference)[0]))
         {  
             if (h.CellValue.InnerText == " ")
             {
                 data.Items.Add(" ");
             }
             else
             {
                 data.Items.Add(GetCellV(h, ssT));
             }

The Program holds a list DataL of Data objects. Each data object has a list of items, if a cell meets the criterion it is added to the list.

However when my program reaches this point it throws me a NullReferenceException, I know this should mean my Data objects were declared and never instantiated like: Data foo = new Data();

Showing Null exception popup

The picture below shows that my Data List is not empty and holds the one data objected that has been created.

Data count = 1

What is causing the exception? Is it because the object is instantiated in a different method, and is then local there?

Full code (without GUI): http://rextester.com/OIV93602

Stack Trace

Stack Trace

Community
  • 1
  • 1
Jack Miller
  • 315
  • 1
  • 14

0 Answers0