Changing the image source of an UI.Image: NullReferenceException

Hi,

I want to change the image source of an Image after an evenement, but I have still this inconprehensive exception: “NullReferenceException: Object reference not set to an instance of an object”.

Here my code

#pragma strict

var balleBloquee : Sprite;

function Start () {
}

function Update () {
if (shootScript.canFire == false){
this.GetComponent(UI.Image).sprite = balleBloquee; <— Exception here
}
}

This script is bound to the UI.Image and in Unity. It would seem that the problem comes from the function “.sprite” since when I use many Debug.Log, this.GetComponent(UI.Image) is ok but this.GetComponent(UI.Image).sprite return null. But I don’t understand why.

Could you help me, please?

Problem solved. I let the script in the old component, hence the exception.