Only 2 lines codebut cannot work

Run the following code ,only 2 line.it cannot work But I get the error:NullReferenceException: Object reference not set to an instance of an object.
How can I get reason? help me,Thanx!

function Update () {
	var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
}

You already asked this, and got an answer, here.

–Eric

It is possible that the ray isnt hitting anything?

No; a ray is not a raycast and doesn’t hit anything anyway.

–Eric