Cannot get variable from another class. Error: NullReferenceException

I want to have a variable containing all game items inside the Item class, but when I try to get the value of GameItemContainer.Container.items it gives me an error.

Item.cs:

public string Name;
public float Price;

// Contructors
public Item() {}
public Item(string itemName)
{
	List<Item> allItems = GameItemContainer.Container.items;
	for (int i = 0; i < allItems.Count; i++) {
		if (allItems*.Name.ToLower() == itemName.ToLower()) {*

_ this.Name = allItems*.Name;_
_ this.Price = allItems.Price;
break;
}
}
}
GameItemContainer.cs:
[XmlArray(“Items”),XmlArrayItem(“Item”)]
public List items = new List ();
public static GameItemContainer Container = LoadXML(“gameItems”);
private static GameItemContainer LoadXML(string xmlname) {
return GameItemContainer.Load (Path.Combine (Application.dataPath, “Scripts/XML/” + xmlname + “.xml”)) as GameItemContainer;
}
public static GameItemContainer Load(string path)
{
XmlSerializer serializer = new XmlSerializer(typeof(GameItemContainer));
using(var stream = new FileStream(path, FileMode.Open))
{
return serializer.Deserialize(stream) as GameItemContainer;
}
}*
Error appears in line
List allItems = GameItemContainer.Container.items;
And it throws the error
NullReferenceException: Object reference not set to an instance of an object
Any help would be greatly appreciated._

Perhaps you should make your entire GameItemContainer class static as well as all members inside it.

Im not sure if this will solve your problem but you should consider a singleton approach, something like this:

public class GameContainer{

    private static GameContainer instance;
    public static GameContainer Instance{
        get{ 
            if(instance == null) instance = new GameContainer();
            return instance;
        }
    }
    
    // constructor should be private
    private GameContainer(){
          // load from XML
    }

     public List<Item> Items = new List<Item> ();

}

you would call it like: GameContainer.Instance.Items, and Instance should never be null, because in this case a new instance is created.