One of my game buttons is giving errors, even though second button with same code works fine?

Hi all,
I am making two buttons in my game, in which one button plays “Spin Attack” animation and other “Double Chop” animation. I have added two separate functions to each button but with exact same code (can see in the code sample below). When I press the Attack Button (AttackButton() function is added to it) in the Unity, it works fine.

But when I press the Spin Attack button (to which SpinButton() function is added to it), its throwing error :-

UnassignedReferenceException: The variable anim of PlayerControllerAndroid has not been assigned.
You probably need to assign the anim variable of the PlayerControllerAndroid script in the inspector.

I have assigned anim variable in the script as you can see in the code and Player Component has been added to it, then why is it throwing this error? Yes, “SpinAttack” and “DoubleChop” are genuine and correct Animation names here.
I am stuck on this issue for a while now, it seems basic problem but please do help!

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

public class PlayerControllerAndroid : MonoBehaviour
{
    
    [SerializeField] private float moveSpeed = 10.0f;
    [SerializeField] private LayerMask layerMask;
    [SerializeField] private FixedJoystick joystick;

    private CharacterController charachterController;
    private Vector3 currentLookTarget = Vector3.zero;
    private Animator anim;
    private BoxCollider[] swordColliders;
    private GameObject fireTrail;
    private ParticleSystem fireTrailParticles;
    // Start is called before the first frame update
    void Start()
    {
        charachterController = GetComponent <CharacterController> ();
        anim = GetComponent <Animator> ();
        swordColliders = GetComponentsInChildren <BoxCollider> ();
        fireTrail = GameObject.FindWithTag("Fire") as GameObject;
        fireTrail.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        if(!GameManager.instance.GameOver)
        {
            Vector3 moveDirection = new Vector3(joystick.Horizontal,0,joystick.Vertical);
            charachterController.SimpleMove (moveDirection*moveSpeed);

            if(moveDirection == Vector3.zero)
            {
                anim.SetBool("IsWalking",false);
            }else{
                anim.SetBool("IsWalking",true);
            }     
        }
    }

    void FixedUpdate()
    {
        Vector3 joystickPosition = new Vector3(joystick.Horizontal,0,joystick.Vertical);  
           
        Quaternion rotation = Quaternion.LookRotation(joystickPosition);
        transform.rotation = Quaternion.Lerp(transform.rotation,rotation,Time.deltaTime*10f);       
    }


    public void BeginAttack()
    {
        foreach (var weapon in swordColliders)
        {
            weapon.enabled = true;
        }
    }
    
    public void EndAttack()
    {
        foreach (var weapon in swordColliders)
        {
            weapon.enabled = false;
        }
    }

    public void speedPowerUp()
    {
        StartCoroutine(fireTrailRoutine());
    }

    IEnumerator fireTrailRoutine()
    {
        fireTrail.SetActive(true);
        moveSpeed = 13f;
        yield return new WaitForSeconds(10f);
        moveSpeed = 6f;
        fireTrailParticles = fireTrail.GetComponent<ParticleSystem> ();
        var em = fireTrailParticles.emission;
        em.enabled = false;
        yield return new WaitForSeconds(3f);
        em.enabled = true;
        fireTrail.SetActive(false);
    }

    public void SpinButton()
    {
        if(!GameManager.instance.GameOver)
            anim.Play("SpinAttack");            
    }

    public void AttackButton()
    {
        if(!GameManager.instance.GameOver)
            anim.Play("DoubleChop");
    }
}

Make anim field as [SerializeField] and look at inspector if that field is correct setted during play. Something make it null during runtime

Test Spin Attack button bind AttackButton() , Check whether it is executed normally.