Array index is out of range && Object reference not set to an instance of an object?

Hi, I’m new in unity and I’m getting these errors with my dialogue system.

Dialogue manager script

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

public class DialogeManager : MonoBehaviour {

    public GameObject DialogeBox;
    public Text TXTName;
    public Text Text;
    public Text Continue;
    public bool DialogeActive;
    public string[] DialogeLines;
    public string Name;
    public int CurrentLine;
    public bool ExitDialoge;

    void Start () {
        DialogeBox.SetActive(false);
        CurrentLine = 0;
        DialogeLines = null;
        Name = null;
        DialogeActive = false;
        ExitDialoge = false;
    }
    
    void Update(){
        if (DialogeActive){
            if (CurrentLine >= DialogeLines.Length){
                DialogeBox.SetActive(false);
                DialogeActive = false;
                CurrentLine = 0;
                DialogeLines = null;
                Name = null;

                ExitDialoge = true;
            }
            else{
                Text.text = DialogeLines[CurrentLine];
                TXTName.text = Name;

                ExitDialoge = false;
            }
            if(Input.GetKeyDown(KeyCode.Space)){
                CurrentLine++;

            }
        }
    }

    public void ShowDialoge(){
        DialogeBox.SetActive(true);
        DialogeActive = true;
    }
}

Dialogue script

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

public class Dialoge : MonoBehaviour{
    
    public string[] Names;
    [TextArea(1, 10)]
    public string[] DialogeLines;
    public int[] WhereToSwitch;
    public bool HaveSpoken;

    private DialogeManager DialogeManger;
    private int CurrentDialogeMember;
    private int WhenToSwitchPosition;

    void Start(){
        DialogeManger = GameObject.FindObjectOfType<DialogeManager>();
        CurrentDialogeMember = 0;
        WhenToSwitchPosition = 0;
        HaveSpoken = false;
    }

    void Update(){
        if (DialogeManger.CurrentLine >= WhereToSwitch[WhenToSwitchPosition]){
            CurrentDialogeMember++;
            WhenToSwitchPosition++;
            DialogeManger.Name = Names[CurrentDialogeMember];
        }
    }

    public void SendDialoge(){
        if (DialogeManger.DialogeActive == false){
            if (HaveSpoken == false){
                CurrentDialogeMember = 0;
                WhenToSwitchPosition = 0;
                DialogeManger.Name = Names[CurrentDialogeMember];
                DialogeManger.DialogeLines = DialogeLines;
                DialogeManger.ShowDialoge();
                HaveSpoken = true;
            }
            else{
                CurrentDialogeMember = 0;
                WhenToSwitchPosition = 0;
                HaveSpoken = true;

            }
        }
    }
}

I’ve created another script to trigger the “SendDialoge” void.

The errors are both in the dialogue script:

  1. Array index is out of range -
    if (DialogeManger.CurrentLine >= WhereToSwitch[WhenToSwitchPosition])
  2. Object reference not set to an instance of an object -
    if (DialogeManger.DialogeActive == false){

WhereToSwitch[WhenToSwitchPosition] - index is greater than the elements in the array
You for example have only 10 elements, and you turn to 15

DialogeManger - connect from inspector this instance, current it’s null