Help with custom EditorWindow

Hi I have i problem that has been bugging me for 2 days now i can’t solve. So i have a custom class with 2 variables, and I want through custom item menu(class that inherits the EditorWindow class) to add elements to an array of this custom class, but i always get a NullReferenceException: Object reference not set to an instance of an object . If it is not an array, but a single variable of this custom class it works, but the moment i make it an array it gives this array. I make sure to initialize the array with new so this is not the problem.

Hi I have i problem that has been bugging me for 2 days now i can’t solve. So i have a custom class with 2 variables.

class CustomClass
{
     object var1;
     object var2;
}

and I want through custom item menu(class that inherits the EditorWindow class) to add elements to an array of this custom class,

class CustomItemMenu : EditorWindow
{
    CustomClass[] array = { }; // empty array of CustomClass

    [MenuItem("Window/Array test")]
    static void ShowWindow()
    {
        GetWindow<CustomItemMenu>().Show();
    }

    void OnGUI()
    {
        GUILayout.Label("array.Length: " + array.Length);

        if (GUILayout.Button("Add"))
        {
            // add element to array
            CustomClass[] newArray = new CustomClass[array.Length + 1];
            for (int i = 0; i < array.Length; ++i)
                newArray _= array*;*_

newArray[array.Length] = new CustomClass();
array = newArray;
}
}
}
> but i always get a NullReferenceException: Object reference not set to an instance of an object. If it is not an array, but a single variable of this custom class it works, but the moment i make it an array it gives this array. I make sure to initialize the array with new so this is not the problem.
Dunno, works for me. However, CustomClass is not serializable so the array will lose contents on script reload.
What exactly is null? The array? The objects in the array? The fields on the objects in the array?
If your custom class have a field of string type, Unity may automatically set null string to empty string when it loads your EditorWindow. However, when you create the object yourself, you are responsible of making sure all fields of CustomClass is set properly.