Recently I'm developing a software that parses and displays XML information from a website. Simple enough right?
I'm getting LOADS of NullReferenceExceptions. For example, this method:
private void SetUserFriends(List<Friend> list)
{
int x = 40;
int y = 3;
if (list != null)
{
foreach (Friend friend in list)
{
FriendControl control = new FriendControl();
control.ID = friend.ID;
control.URL = friend.URL;
control.SetID(friend.ID);
control.SetName(friend.Name);
control.SetImage(friend.Photo);
control.Location = new Point(x, y);
panel2.Controls.Add(control);
y = y + control.Height + 4;
}
}
}
I had to wrap an ugly as sin If around the actual foreach loop in order to prevent an exception.
I feel I'm just putting bandaids on a flat tire instead of actually fixing the problem. Is there any way I can tackle this problem? Maybe a book I should read regarding programming patterns or what not?
Really, I'm lost. I'm probably asking the wrong questions.