Object reference not set to an instance of an object

Hi! I’ve been working on an Unity Editor Window.
I’m using a List, and want to create and add the created object to the list.

		if (GUILayout.Button ("Add Element")) {
			objects.Add(new GameObject("Element");
		}

I’ve written this code, the object named “Element” is created but saying that it is not set:
NullReferenceException: Object reference not set to an instance of an object

What’s wrong with the code? :confused:

Rookie mistake here.
objects must be null. Do print(objects); just before, and see if it prints null.

I think you didn’t initialized your list properly. Lists must be initialized before using like this:

List<contentType> name = new List<contentType>();