[Solved][is it a bug?]null refrence error using a getcomponent()

Hello every one im geting null refrence error using the code getcomponent() for my ui image.

I dont know where I am wrong because when I use
debug.log(getcomponent())
Unity detect the component
And im using name space unityengine.ui
I khow how to use the code and I’ve used this code before somewhere else and it worked
It’s very annoying situation
Please help me out.
Update:
Actually I’m trying to make a joystick for android and i was wrong debug.log() doesn’t detect the component it says (null refrence error, an instances of the object…) And here is the code .my entire project depends on this , any possible solutions are welcome

using UnityEngine;
using UnityEngine.UI;

public class joyStick : MonoBehaviour
{

    private Vector3 pointA;
    private Vector3 pointB;

    public Vector3 offset;
    public Vector2 bulletDirection;
    private Vector2 myTouchPosition;
    private Touch myTouch;
    private int touchID;
    public GameObject outerCircle;
    
    private void Start()
    {
        
        outerCircle = GameObject.Find("outerCircle");
    }
    private void Update()
    {




        touchSelection();




        

        if (myTouch.phase == TouchPhase.Moved && myTouch.fingerId == touchID)
            {
                myTouchPosition = myTouch.position;
                pointB = new Vector3(myTouchPosition.x, myTouchPosition.y, Camera.main.transform.position.z);
                offset = pointB - pointA;
                pointB = pointA + Vector3.ClampMagnitude(offset, 60);
                offset.Normalize();
                transform.position = pointB;
            }
        if (myTouch.phase == TouchPhase.Ended && myTouch.fingerId == touchID)
        {
           offset = Vector3.zero;
           outerCircle.GetComponent<Image>().enabled = false;
           GetComponent<Image>().enabled = false;
        }
    }


    private void touchSelection()
    {
        int i = 0;
        while(i<Input.touchCount)
        {
            myTouch = Input.GetTouch(i);
            myTouchPosition = myTouch.position;
            if(myTouch.phase == TouchPhase.Began)
            {
                if (Input.GetTouch(i).position.x <Screen.width/2)
                {
        
                    touchID = myTouch.fingerId;
                    outerCircle.transform.position = myTouchPosition;
                    outerCircle.GetComponent<Image>().enabled = true;
                    transform.position = myTouchPosition;
                    GetComponent<Image>().enabled = true;

                }
            }
            

            ++i;
        }
    }

I found the reason which might not be completely related to the question and the code is almost fine and works but i changed it a bit using for loop instead of while in touchseletion method and making a refrence for the gameobject this script is attached t and some more little changes which wasn’t necessary.

But the real problem was i has duplicated the ui image in hierarchy window and disabled this for back up because i wasn’t sure about what I was doing.And I guess unity was trying to access the disabled ui image whenever i attempted to refrence that which shouldn’t be so. Since I deleted the back up gameobject i was able to make thing works

I hope this solved your problem too.