Getting NullReferenceException when creating class instance using List

I’m trying to create instance of class using List instead of array and getting error ,
i don’t know the exact cause

please let me know if there is any workaround to use List of Class objects
Thanks in advance for any suggestion or code !

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
    
[System.Serializable] public class BaseClass{
public int index ;
public  List<GameObject> itemList;
}

public class GameLogicClass : MonoBehaviour {

public List<BaseClass> baseClassInstance;


	void Start(){

		for(int _m = 0;_m < 10;_m++){

					baseClassInstance.Add(new BaseClass());
					baseClassInstance[_m].index = 1;

		}

		Debug.Log(baseClassInstance[0].itemList.Count );  // < Getting ERROR here : NullReferenceException: Object reference not set to an instance of an object GameLogicClass.Start () 

	}
}

I think you need to define what the list is of (though this may be optional as it sounds like you aren’t getting an error here)

public List<BaseClass> baseClassInstance;

and you need to initialise the list somwhere:

void Start(){
	baseClassInstance = new List<BaseClass>();
	for(int _m = 0;_m < 10;_m++){
		baseClassInstance.Add(new BaseClass());
		baseClassInstance[_m].index = 1;
	}
	Debug.Log(baseClassInstance[0].itemList.Count );
}

Also in future can you highlight all your code and hit the ‘101010’ button or press ‘Ctrl+K’ to format your code!

Thanks,

Scribe