title: C# a having a list inside a list of objects. Will not allow .add
body: <p>I keep getting this error. </p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.NullReferenceException' occurred in CustomerExcelreader.exe</p>
  </blockquote>
  
  <p>Additional information: </p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>Which I don't know why, since I have a global object, and I know the object works, since when I use non-list values of the object, everything works just fine.</p>
  
  <p>This is the actual object in question.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace CustomerExcelreader
  {
  public class customers
  {
      public customers()
      {
  
      }
      /// &lt;summary&gt;
      /// These work just fine.
      /// &lt;/summary&gt;
      public String Guest { get; set; }
      public String Contact { get; set; }
      public String ClubNumber { get; set; }//GuestNumber
      public String CasioNumber { get; set; }
  
      /// &lt;summary&gt;
      /// Lists of lists
      /// &lt;/summary&gt;
      public List&lt;String&gt; Dates { get; set; }
      public List&lt;String&gt; Description { get; set; }
      public List&lt;Double&gt; moneyIN { get; set; }
      public List&lt;Double&gt; moneyOUT { get; set; }
      public List&lt;Double&gt; Balance { get; set; }
      public List&lt;String&gt; Remarks { get; set; }
  
  }
  }
  </code></pre>
  
  <p>and here is where it messes up with any of the List values, but normal variables are fine.</p>
  
  <pre><code>private void addButton_Click(object sender, EventArgs e)
  {
      //customers add_customerHistory;
      if (listNames.SelectedIndex &gt;= 0)// &amp;&amp; listNames.SelectedIndex &lt;= Pathlist.Capacity)//somehow SelectedIndex could be less then 0 by not picking something.
      {
          //add_customerHistory = CustomerHistoryList[listNames.SelectedIndex];
          textBox1.Text = CustomerHistoryList[listNames.SelectedIndex].ClubNumber;
          CustomerHistoryList[listNames.SelectedIndex].Dates.Add(DateBox.Text);
          CustomerHistoryList[listNames.SelectedIndex].Description.Add(DescriptionBox.Text);
          CustomerHistoryList[listNames.SelectedIndex].moneyIN.Add(Convert.ToDouble(InBox.Text));
          CustomerHistoryList[listNames.SelectedIndex].moneyOUT.Add(Convert.ToDouble(OutBox.Text));
          CustomerHistoryList[listNames.SelectedIndex].Balance.Add(Convert.ToDouble(BalanceBox.Text));
          CustomerHistoryList[listNames.SelectedIndex].Remarks.Add(RemarkBox.Text);
          //CustomerHistoryList[listNames.SelectedIndex].CasioNumber = "Its been changed";
          richTextBox1.Text = CustomerHistoryList[listNames.SelectedIndex].CasioNumber;
  
      }
      else
      {
          CustomerHistoryList[0].Dates.Add(DateBox.Text);
          CustomerHistoryList[0].Description.Add(DescriptionBox.Text);
          CustomerHistoryList[0].moneyIN.Add(Convert.ToDouble(InBox.Text));
          CustomerHistoryList[0].moneyOUT.Add(Convert.ToDouble(OutBox.Text));
          CustomerHistoryList[0].Balance.Add(Convert.ToDouble(BalanceBox.Text));
          CustomerHistoryList[0].Remarks.Add(RemarkBox.Text);
      }
  
  }
  </code></pre>
  
  <p>It seems odd that it doesn't work here. I guess it has something to do with lists inside of objects? I heard those can act funky.</p>