Fixing null pointer exception bug when creating new records