title: "Object reference not set to an instance of an object" when trying to access a classes nested list
body: <p>I am writing a C# UWP program to track weather data. When trying to access the line   <code>Debug.WriteLine("DEBUG IN WEATHERPAGE: " + myForecast.mysortedDays[1][1].desc);</code> in the WeatherPage Class I am getting the "Object reference not set to an instance of an Object". <code>sortedDays</code> is a nested list which I need to be able to access fully. I know that in my <code>GetWeather</code> method <code>sortedDays</code> is populating but is null when referenced from another class. I feel it would be a case of calling a setter method but not I am unable to do this successfully with a linked list</p>
  
  <pre><code>namespace WeatherForecast
  {
  /// &lt;summary&gt;
  /// An empty page that can be used on its own or navigated to within a Frame.
  /// &lt;/summary&gt;
  public sealed partial class WeatherPage : Page
  {
      Forecast myForecast;
      public WeatherPage()
      {
          this.InitializeComponent();
  
           myForecast = new Forecast();
          // Task task =myForecast.GetWeather("id=2964179");
  
          myForecast.GetWeather("id=2964179");
  
          Debug.WriteLine("DEBUG IN WEATHERPAGE: " + myForecast.sortedDays[1][1].desc);
      }
  }
  }
  
  
  namespace WeatherForecast
  {
  class Forecast
  {
      public List&lt;List&lt;WeatherController&gt;&gt; sortedDays { get; set; }
      public RootObject result { get; set; }
  
      public Forecast()
      {
  
      }
   public async void GetWeather(string cCode)
      {
          // DEBUG
          Debug.WriteLine("DEBUG: Started getWeather");
          string cityCode = cCode;
          string apiKey = "myapikey";
          // string cityCode = "id=2964179";
          string url = "myurl" + cityCode + apiKey;
  
  
          var uri = new Uri(url);
          using (HttpClient client = new HttpClient())
          {
              using (HttpResponseMessage response = await client.GetAsync(uri))
              {
                  using (IHttpContent content = response.Content)
                  {
                      var json = await content.ReadAsStringAsync();
  
                      result = JsonConvert.DeserializeObject&lt;RootObject&gt;(json);
                      //  SortWeather();
  
                      // create a list of weatherController lists to hold each day
                      // made public for global access
                      List&lt;List&lt;WeatherController&gt;&gt; sortedDays = new List&lt;List&lt;WeatherController&gt;&gt;();
                      //    sortedDays = new List&lt;List&lt;WeatherController&gt;&gt;();
  
                      //create a list of weatherController objects to hold each hourly interval
                      List&lt;WeatherController&gt; sortedHours = new List&lt;WeatherController&gt;();
  
                      // a base time
                      DateTime prevDate = Convert.ToDateTime("2000-01-01");
                      int counter = 0;
  
                      // iterate through result list  
                      for (int i = 0; i &lt; result.list.Count(); i++)
                      {
                          // if the date is greater than the previous date add the sortedHours to sortedDays
                          if (Convert.ToDateTime(result.list[counter].dt_txt).Date &gt; prevDate.Date &amp;&amp; counter != 0)
                          {
                              sortedDays.Add(sortedHours);
                              sortedHours = new List&lt;WeatherController&gt;();
                          }
                          WeatherController wController = new WeatherController
                          {
                              dtime = result.list[counter].dt_txt,
                              dayOfWeek = (Convert.ToDateTime(result.list[counter].dt_txt).DayOfWeek).ToString(),
                              temp = result.list[counter].main.temp,
                              humidity = result.list[counter].main.humidity,
                              desc = result.list[counter].weather[0].description,
                              windSpeed = result.list[counter].wind.speed
                          };
                          sortedHours.Add(wController);
  
                          prevDate = Convert.ToDateTime(result.list[counter].dt_txt);
                          counter++;
  
                      }
                      // add any left over sortedHours to sortedDays
                      if (sortedHours != null)
                      {
                          sortedDays.Add(sortedHours);
                      }
  
                      Debug.WriteLine("DEBUG: Finished getWeather");
  
                  }
              }
          }
      }
  
  
  }
  }
  </code></pre>