So my code basically sets up a linked list. Each ticket object either stores the reference to another ticket object, or null. The .getNext() method gets the reference to the next object in the list. current is the object representing the start of the list and the while loops go through the list changing current until the conditions change. Finally, it sets current to the Ticket that was passed as a parameter.
public void AddLowPTicket(Ticket ti) // doesnt check if front == null because AddTicket already does
{
Ticket current = front;
while(current.getPrio() == Priority.High && current != null) // cycles/skips through the list as long as Priority == High.
{
current = current.getNext();
}
current.Print(); // *THIS WORKS*
while(current != null && current.getPrio() == Priority.Low) // *NullReferenceException: Obj ref not set to an instance of an obj.*
{
current = current.getNext();
}
current = ti;
}
This is the Print method for the Ticket object. It prints the local variables just fine, which means they aren't null.
public void Print()
{
Console.WriteLine("{0}\nPriority:{1}", m_description, m_prio == Priority.High ? "High" : "Low");
}
Why does it crash if current is not null, and none of its variables are either.