Class Inheritance: Calling class object method yields Object Reference not set to an instance of an object

The full error is: NullReferenceException: Object reference not set to an instance of an object
SpawnPlayer.Start () (at Assets/Scripts/SpawnPlayer.cs:29)

I have 3 classes. One for spawning Monster, MonsterDatabase and SpawnPlayer. I would call the method MonsterDatabase.Populate() to create the monster tables filling the Monster properties. It would then store them in an Array. SpawnPlayer will load the corresponding monster (and in another script EnemyMonster). I am not sure why but I am getting this error. I am not sure why I cant call the method in the SpawnClass. If anything it is more like an abstract container for monsters but even as an abstract method I cannot call the method.

Source Files:
SpawnPlayer.cs
MonsterDatabase.cs
Monster.cs

Edit: Wooooow. Im an idiot.

Answer: I had to set the MonsterDatabase.cs as static since I am not creating an instance of it…

In SpawnPlayer.cs, the variable MonsterDatabase is never initialized, and will always be null. You need to set that variable to an instance first before you can call methods on it. Ordinarily, you might do something like this (in SpawnPlayer.cs):

    // Use this for initialization
    void Start()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
        if (spriteRenderer == null)
        {
            Debug.Log("The player sprite cannot be null");
        }
 
        //Generate the monster table
        MonsterDatabase = new MonsterDatabase(); // this is the missing call
        MonsterDatabase.Populate();
 
        //Assign a monster to a player
        PlayerMonster = MonsterDatabase.monsters[0];
 
        //Since this class is spawning the player we will concatenate string + "_b"
        //because we want to load the back end of the sprite
        string spriteFile = PlayerMonster.SpriteFile+"_b";
        spriteRenderer.sprite = Resources.Load<Sprite>("Sprites/" + spriteFile);
    }

However, as you mentioned, MonsterDatabase is abstract, so you can’t create a new instance of it. You haven’t yet mentioned why MonsterDatabase is abstract, so I would first ask, does it need to be? Do any classes inherit from it? For example, is there an EnemyMonsterDatabase class and a FriendlyMosterDatabase class or something similar? If not, just remove the abstract tag and you should be able to use the above code.