error "Object reference not set to an instance of an object" RRS feed

  • Question

  • hello, 

    I have this error, when I do that:  pageTitle.Text = listFilterTitle.NomeEscola;

    in my code I can pass a value and compare...

    this is my code: 

     List<Escola> ListTitle = new List<Escola>();
       db.RunInTransaction(() =>
                            ListTitle = db.Query<Escola>("Select NomeEscola from Escola");
    var listFilterTitle = ListTitle.Where(escola => escola.ID_Escola.ToString() == idEscola).FirstOrDefault();
      pageTitle.Text = listFilterTitle.NomeEscola;


    Tuesday, October 22, 2013 2:37 PM


  • It sounds like either pageTitle or listFilterTitle is null. The first thing to do is to check which in the debugger. You might need to use DefaultIfEmpty().First() instead of FirstOrDefault if the default doesn't return the needed object.


    Tuesday, October 22, 2013 3:17 PM