Hi trying to find the cause of the error message found in the code below, still new to learning C# so any help is much appreciated :)
private static void DisplayTransaction(Transaction transaction)
{
string type = transaction.getType();
string date = transaction.getDate().ToString();
string id = transaction.getItem().getID().ToString();
string itemname = transaction.getItem().getItemName();
if(type == "add")
{
string price = transaction.getPrice().ToString();
Console.WriteLine("\t{0, -19} {1, -6} {2, -3} {3, -10} {4, -10} {5, -5}",
date,
type,
id,
itemname,
"",
price);
}
else
{
string name = transaction.getEmployee();
Console.WriteLine("\t{0, -19} {1, -6} {2, -3} {3, -10} {4, -10} {5, -5}",
date,
type,
id,
itemname,
name,
"");
}
}
This line keeps throwing "System.NullReferenceException: 'Object reference not set to an instance of an object.'
Software_Assignment.Transaction.getItem(...) returned null."
string id = transaction.getItem().getID().ToString();