Help with turning a random gen # into text mesh.

I keep getting an error “NullReferenceException: Object reference not set to an instance of an object
RandomGen1.RandGen () (at Assets/RandomGen1.cs:13)
UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:166)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()”
I think I know why but I’m not completely sure the code is

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

public class RandomGen1 : MonoBehaviour
{

    public GameObject TextBox;
    public int RandomNum;

    public void RandGen() {
        RandomNum = Random.Range(1, 1000);
        TextBox.GetComponent<Text>().text = "" + RandomNum;
    }
}

I think it has to do with because it is trying to find a text box but I don’t have one since i’m using the text mesh boxes but I’m not 100% sure.

Post removed.

Follow the rules. This error can be solved with 5 minutes at google