Problem with Image and Sprite

Hi all, I have one question that i have tried to resolve but i could not.

I have this var: public Image soundImage;
(I drag and drop the image in the inspector)

And i call a function to switch the sound sprite when i press a button. The function contains :

if (sound) {
            soundImage.sprite = spriteSoundOn;
            sound = false; 
}else{
            ....

The var spriteSoundOn it is also in the inspector ( I tried with spriteSoundOn = = Resources.Load<Sprite> (sprite path); but it did not work

The problem gives me unity in the line soundImage.sprite = spriteSoundOn; is:

NullReferenceException: Object reference not set to an instance of an object
GameState.Sound () (at Assets/Scripts/GameState.cs:118)
UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:154)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:637)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:773)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:52)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()

This error shows only 2 issues,

  1. soundImage may not be assigned.
    or
  2. spriteSoundOn may not be assigned.

either one of the above will cause the error,

You have mentioned you are drag and dropping image for sound image in inspector.

So, the only error could be spriteSoundOn might have been unassigned or null.
You have mentioned
( I tried with spriteSoundOn = = Resources.Load (sprite path):wink:

Solution:
1.Check whether the name of path is correct with the sprite in the resource folder.
or
2.Expose the spriteSoundOn variable in inspector and assign it with the sprite.

To double check it print log and see if spriteSoundOn is null or soundImage is null.
@Morwin25