Why do I get an error when instantiating?

I use this code and when I hit play I get an error that says that the variable rock has not been defined, but I already dragged the prefab in the inspector and actually, the rocks get instantiated.

public GameObject rock;

void Start () {
	for (int i = 0; i < 5; i++)
		Instantiate (rock, new Vector3 (i*0.5f, i * 1.3f, 0f), Quaternion.identity);

Try this :

Instantiate (rock, new Vector3 (i*0.5f, i * 1.3f, 0f), Quaternion.identity) as GameObject;

Have you dragged the rock prefab onto the rock object in the inspector for that class?
It looks like it is trying to instantiate a rock when its not defined i.e. its null

This might help you to figure it out:

Debugging is always good:
Before your for loop statement, try Debug.Log(rock) to see if it printsnull. If it does, either there is a problem with what you’ve done in the inspector or you are doing something else with rock that sets it null.

Maybe you have some garbage GameObject with your script attached:
If you are sure that you didn’t mess around with the variable rock, use the search for the script you have created in the search function on the top of the hierarchy panel to to see all of the GameObjects that has that component attached.

Unity’s wierdness:
Try to delete the attached component in the inspector and add it again. Who knows?