Getting nullreference error while using sendmessage

I’m trying to iteratively generate 10 GUI.buttons to use as a skill bar . Each button’s function needs to be customizeable, so I have a string array that I use in conjunction with sendmessage to indicate which skill’s function (from a large database of functions I keep in a separate script) should be run when the button is activated. Right now, it reads as follows:

private string[] buttonAction;

void OnGUI(){
DisplayActionBar ();
}

public void DisplayActionBar(){
for (int cnt = 0; cnt < 10; cnt++) {
buttonAction[cnt] = "NoSkill";
if (GUI.Button (new Rect ((Screen.width / , (Screen.height - 100), 50, 50), blankActionTexture, "label")) {
gameObject.SendMessage (buttonAction[cnt]);
}
}

}

This doesn’t pop an error while in unity, but when I run it, it tells me:

NullReferenceException: Object reference not set to an instance of an object
(wrapper stelemref) object:stelemref (object,intptr,object)
ActionBar.DisplayActionBar () (at Assets/Scripts/HUD Classes/ActionBar.cs:44)
ActionBar.OnGUI () (at Assets/Scripts/HUD Classes/ActionBar.cs:31)

Two scripts are being used- Action Bar, which is the tiny function that draws my bar and lets me drag & drop icons, and ActionDatabase, which contains functions for each skill (and a debug function NoSkill that gets called if the player activates an empty skill box). Both scripts are attached to the same object, Is gameObject.sendmessage somehow not finding ActionDatabase?

There is no place in your code where you instantiate buttonAction. Based on how you iterate through it in the for-loop in method DisplayActionBar, I take it you expect it to be a string array of size 10. But where did you tell C# that? You’re supposed to initialize it first:

buttonAction = new string[10];

If you don’t, it will remained declared, so the reference exists and thus does not cause compiler errors, but not instantiated, so the reference points to null. When one attempts to use a reference type variable that points to null, you get a NullReferenceException.