private void AddDevotions()
{
for (int i = 1; i <= 366; i++)
{
string filePath = "Devotions/Devotion1" + i.ToString() + ".txt";
devotions.Add(d);
}
}
Since your code never sets the auto property
d
to anything,
every item in your
devotions
list will be
null
. When you try to call
.ToString()
on a
null
reference, you will get a
NullReferenceException
.
I suspect that you meant to read the file from
filePath
into the list? If so, try the following:
private void AddDevotions()
{
for (int i = 1; i <= 366; i++)
{
string filePath = Path.GetFullPath("Devotions/Devotion1" + i.ToString() + ".txt");
if (File.Exists(filePath))
{
devotions.Add(File.ReadAllText(filePath));
}
else
{
devotions.Add(string.Format("Devotions file '{0}' was not found.", i));
}
}
}