In my program, I'm getting the error:
An unhandled exception of type 'System.NullReferenceException' occurred in POS System.exe
Additional information: Object reference not set to an instance of an object.
This happens when I try to add something to TransactionList as shown below. TransactionList is a list of class instances, declared like this:
public static List<Transaction> TransactionList { get; set; }
And this is the Transaction class:
class Transaction
{
public double TotalEarned { get; set; }
public double TotalHST { get; set; }
public double TotalCost { get; set; }
public string Category { get; set; }
public int DaysSince2013 { get; set; }
}
Any clue whats wrong here? I can't seem to find why this error is being thrown... Thanks!
for (int i = 0; i < (lines / 5); i++)
{
TransactionList.Add(new Transaction //Error happens on this line
{
TotalEarned = Convert.ToDouble(stringArray[(i * 5)]),
TotalCost = Convert.ToDouble(stringArray[(i * 5) + 1]),
TotalHST = Convert.ToDouble(stringArray[(i * 5) + 2]),
Category = stringArray[(i * 5) + 3],
DaysSince2013 = Convert.ToInt32(stringArray[(i * 5) + 4])
});
}
TransactionListorstringArrayare most likelynull.