The error 'Attempt to dereference a null object' often occurs when trying to access a member of a null object. By checking if the object is null in the getter method and returning a new instance if it is, the error can be prevented. References: Apex Developer Guide