I am trying to add an object to a list of objects in c#, and i get an System.NullReferenceException: Can someone figure out why?
This is the code;
public List<PodcastShow> Podcasts { get; set; }
public BLL()
{
Podcasts = new List<PodcastShow>();
Categories = new List<Category>();
rssR = new RSSreader();
} //contructor
public void newPodcast(string url, string category, string frequency)
{
PodcastShow newPod = new PodcastShow(url, category, frequency);
addToPodcastList(newPod);
}
private void addToPodcastList(PodcastShow newPod)
{
Podcasts.Add(newPod); <--- this is the place i get the nullrefrence exeption is thrown
}
i do instanciate BLL in a form
public Form1()
{
InitializeComponent();
timer1.Start();
timer2.Start();
timer3.Start();
bll = new BLL();
WebClient client = new WebClient();
bll.getPodcastShos();
FillLvPodcast();
PopulateCategoryList();
}
This is the button wich calls on the newPodcast method:
string url = txtURL.Text;
string cat = cboKategori.Text;
string updtF = cboUppdateringsfrekverns.Text.ToString();
bll.newPodcast(url, cat, updtF);
ListViewItem podcastItem = new ListViewItem(bll.getPodcastTitleUrl(txtURL.Text));
podcastItem.SubItems.Add(cboUppdateringsfrekverns.Text);
podcastItem.SubItems.Add(cboKategori.Text);
var counter = bll.podCastEpCounter(bll.getPodcastTitleUrl(txtURL.Text));
lvPodcast.Items.Add(podcastItem);
lvEpisodes.Items.Add(counter.ToString());
bll.serializePodcastShow();
this is the exception i get System.NullReferenceException: Object reference not set to an instance of an object.
Logic.BLL.Podcasts.get returned null.