I do not see anything wrong in the code you shared. It looks exactly like the sample, except Map was renamed.
Check everywhere for GraphicsLayer, maybe it fails to retrieve the layer somewhere else not in this line. Check the call stack, this usually tells you which code was executed before the NullReference exception.