NullReferenceException: Object reference not set to an instance of an object error

I am creating a sprinting mechanic but when I try to change the Speed variable of my movement script I get a NullReferenceException. I already tried everything but it keeps comming back because the getcomponent keeps failing.
Thanks for helping!

Thijs

The CharacterMovement script:

using UnityEngine;
using System.Collections;

public class CharacterMovement : MonoBehaviour {

    Rigidbody Rigidbody;
    public float Speed;
    public Vector3 Movement;
    // Use this for initialization
    void Start () {
        Rigidbody = GetComponent<Rigidbody>();
	}
	
	// Update is called once per frame
	public void Update () {
        float Horizontal = Input.GetAxisRaw("Horizontal");
        float Vertical = Input.GetAxisRaw("Vertical");
        Movement = new Vector3(Horizontal, 0, Vertical);
        Rigidbody.velocity = Movement * Speed;
	}
}

using UnityEngine;
using System.Collections;

And the Stamina script:

public class Stamina : MonoBehaviour {

    public float maxStamina;
    public float currentStamina;
    public float staminaRegen;
    public float sprintDecr;
    public float movement;
    public float sprintSpeed;
    public float runSpeed;
    public bool moving;
    public bool isSprinting;
    public float sprintTest;
    CharacterMovement CC;
    GameObject cube;


    void Start () {

    }
	
	
	void Update () {
        movement = Input.GetAxisRaw("Horizontal") + Input.GetAxisRaw("Vertical");
        MovementCheck();
        SetStaminaMax();
        Sprinting();
        sprintTest = Input.GetAxisRaw("Sprint");
        cube = GameObject.Find("Cube");
        CC = cube.GetComponent<CharacterMovement>();
    }


    public void MovementCheck()
    {
        if (movement == 0)
        {
            moving = false;
        }
        else
        {
            moving = true;
        }
    }

    public void SetStaminaMax()
    {
        if (currentStamina <= 0)
        {
            currentStamina = 0;
        }
        if (currentStamina >= maxStamina)
        {
            currentStamina = maxStamina;
        }
    }

    public void Sprinting()
    {
        if (Input.GetAxisRaw("Sprint") > 0 && currentStamina > 0 && !isSprinting && moving)
        {
            CC.Speed = sprintSpeed;
            isSprinting = true;
        }
        else
        {
            CC.Speed = runSpeed;
            isSprinting = false;
        }
    }
}

I have yet to add a stamina regeneration and stamina decrease but all the values are set in the editor so everything should work.

CharacterMovement script:

public float v,h; // so we can cheek movement from other script 
void Update () {
     h = Input.GetAxisRaw("Horizontal");
     v = Input.GetAxisRaw("Vertical");
     Movement = new Vector3(h, 0, v);
     Rigidbody.velocity = Movement * Speed;
 }

Stamina script:

void Start () {
      if (cube != null){
         CC = cube.GetComponent<CharacterMovement>();// no need to be in Update()
     }
 }
 void Update(){
     MovementCheck();
     SetStaminaMax();
     Sprinting();
 }
 void MovementCheck(){
     if(CC.v == 0 && CC.h == 0){
          moving = false;
     }else if(CC.v != 0 || CC.h != 0){
          moving = true;
     }
 }
void Sprinting(){
    if(Input.GetButtonDown("Sprint") && moving){ //when holding the button
        if(currentStamina > 0){
              CC.Speed = sprintSpeed;
        }
    }
    else if(Input.GetButtonUp("Sprint")){ // when releasing the button
         CC.Speed = normalSpeed;
    }
}

so i have imagined that what you want if the shift button is pressed & currentStamina > 0 should sprint but you have to not sprint when releasing the shift button that’s why i replaced Input.GetAxisRaw with Input.GetButtonDown & Input.GetButtonUp . if this not exactly what you want just tell me don’t hesitate .