Getting nullreference

Hi ı have 8 buttons and their names are button_1 button_2… button_8.Im trying to save as gameobject and every 8 buttons has this script cause ım using onmouseover and every one of them has to has this right? I m getting nullreference on line 8 İt works when ı add buttons=new Gameobject[8]. I dont understand why ı have to declare arrays size.Just take what ı give

 GameObject[] buttons;
    private void Awake()
    {
        for(int i = 0; i < 8; i++)
        {
            for (int a = 1; a < 9; a++)
            {
                buttons[i] = GameObject.Find("button_"+a.ToString());

            }


        }
 
    }
    void Start()
    {
        for (int a = 2; a < buttons.Length; a += 2)
        {
          //  buttons[a].SetActive(false);


        }
    }

    // Update is called once per frame
    void Update()
    {
   
    }

    private void OnMouseOver()
    {
        hide_button();
    }
    private void OnMouseExit()
    {
   
    }


    void hide_button()
    {
      switch(gameObject.name)
        {
            case "1":
                buttons[2].SetActive(true);
                break;
            case "3":
                buttons[2].SetActive(true);
                break;
            case "5":
                buttons[2].SetActive(true);
                break;
            case "7":
                buttons[2].SetActive(true);
                break;


        }



    }

The answer never changes.

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Steps to success:

  • Identify what is null
  • Identify why it is null
  • Fix that
    GameObject[] buttons;
    private void Awake()
    {
        buttons = new GameObject[8];
            for (int a = 1; a < 9; a++)
            {
          
                buttons[a-1] = GameObject.Find("button_" + a.ToString());

            }


      
     
    }
    void Start()
    {
        for (int a = 1; a < buttons.Length; a += 2)
        {
            buttons[a].SetActive(false);


        }
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    private void OnMouseOver()
    {
        Debug.Log("anan");
        hide_button();
    }
    private void OnMouseExit()
    {
        show_button();
    }


    void hide_button()
    {
      switch(gameObject.name)
        {
            case "button_1":
                buttons[1].SetActive(true);
                break;
            case "button_3":
                buttons[3].SetActive(true);
                break;
            case "button_5":
                buttons[5].SetActive(true);
                break;
            case "button_7":
                buttons[7].SetActive(true);
                break;


        }



    }
    void show_button()
    {
        switch (gameObject.name)
        {
            case "button_2":
                buttons[1].SetActive(false);
                break;
            case "button_4":
                buttons[3].SetActive(false);
                break;
            case "button_6":
                buttons[5].SetActive(false);
                break;
            case "button_8":
                buttons[7].SetActive(false);
                break;


        }

    }

this works