How can i fix this error message? NullReferenceException: Object reference not set to an instance of an object PlayerName.StoreName

This is my Code

using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;

public class PlayerName : MonoBehaviour
{
public string theName;
public Text inputField, textDisplay;

[Space]
public List<string> storedPlayerNames = new List<string>();

public void StoreName()
{
    theName = inputField.text;
    textDisplay.text = textDisplay.text + "

" + theName;

    if (storedPlayerNames.Contains(theName))
        Debug.LogWarning(theName + " already exists", this);

    else
    {
        storedPlayerNames.Add(theName);
        Debug.Log("New player added: " + theName);
    }
}

}

“A NullReferenceException happens when you try to access a reference variable that isn’t referencing any object. If a reference variable isn’t referencing an object, then it’ll be treated as null. The run-time will tell you that you are trying to access an object, when the variable is null by issuing a NullReferenceException.”
Unity - Manual: Null Reference Exceptions

You Are trying to access something that isn’t there. At a glance the problem seems to lie in the public variables at the top:

maybe you forgot to assign them in the inspector? Check if they are empty.