locked
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;

    thanks

    Tuesday, October 22, 2013 2:37 PM

Answers

  • 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.

    --Rob

    Tuesday, October 22, 2013 3:17 PM
    Moderator