Why am I getting a null reference?

if (response is IList)
IList buddy = (List) response;
for(int i=0;i<buddy.Count;i++){

				Debug.Log("Buddy request from: " + buddy*.GetBuddyName());* 

GetBuddyRequest.buddy_requests = buddy_requests_list.ToArray();
public static string[] buddy_requests;
void OnGUI(){

* {*
* scrollPosition = GUI.BeginScrollView(new Rect(Screen.width - 950, Screen.height - 400, 100, 200), scrollPosition, new Rect(0, 0, 0, 1000));*
* buddy_selected = GUILayout.SelectionGrid(buddy_selected, buddy_requests, buddy_requests.Length);

* }*
so the code is generating a buddy list then i’m converting it to an array and putting it into the buddy_requests variable. But I’m still getting a null reference error on the line buddy_selected = GUILayout.SelectionGrid(buddy_selected, buddy_requests, buddy_requests.Length); And I’m not sure why, I use code identical to this in another script and seems to work fine.

The only thing in the line you mention that can give a Null reference exception is that

public static string[] buddy_requests;

is null at the time OnGUI is called. since buddy_requests.Length would be null.Length.
Try putting a Debug where you first set buddy_requests, and a Debug at the beginning of OnGUI to see which is called first.

i think it’s because you are using a variable that is only initiated inside an if statement, mean that it is possible that it will never initiate, and so you get a null reference exception