Results 1 to 3 of 3

Thread: [RESOLVED] NullReferenceException when adding to list

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Resolved [RESOLVED] NullReferenceException when adding to list

    I thought that I knew how to handle those NullReferenceExceptions...but I simply don't know what to do with this one

    Part of my Code:

    Code:
            public class Chapter
            {
                public string Name;
                public TimeSpan Time;
            }
    
            public class ChapterSet
            {
                public List<Chapter> Chapters;
            }
    
            public ArrayList GrabChapters(string searchString)
            {
               
                ...(Unimportant code)...
    
                foreach (XmlNode node in NodeList)
                {
                    ChapterSet chapterSet = new ChapterSet();
    
                    XmlNodeList chapters = node.ChildNodes;
                    foreach (XmlNode chapter in chapters)
                    {
                        Chapter pChapter = new Chapter();
                        pChapter.Name = chapter.Attributes["name"].Value;
                        pChapter.Time = TimeSpan.Parse(chapter.Attributes["time"].Value);
    
                        chapterSet.Chapters.Add(pChapter);
                    }
    
                    Results.Add(chapterSet);
                }
    
                return Results;
            }
    Anyone that can give a good explanation why this happens? (On the red line)
    Last edited by Cyb3rH4Xter; Jun 26th, 2011 at 09:41 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width