"Can't save null entries in the string array"

Hi,

I’m trying to store ‘books’ (a name and a description), in player prefs by turning my List elements into one long string and storing that in a string array, to then save, and then load and unravel when the game begins.

I have this to do so:

		if (GUI.Button (new Rect (10, 150, 100, 25), "Save")) 
		{

			for(int i = 0; i < gamecontroller.levelsList[0].BookList.Count; i++)
			{

				newArray <em>= (gamecontroller.levelsList[0].BookList_.bookName + gamecontroller.levelsList[0].BookList*.bookContents).ToString ();*_</em>

_ print (newArray*);*_

* PlayerPrefsX.SetStringArray(“book_key”, newArray);*

* }*

* }*
However, this gives me this error (which is strange because the print above it gives what I need)
[27668-screen+shot+2014-06-13+at+12.16.21.png|27668]

Full error is this:
Can’t save null entries in the string array when setting book_key
UnityEngine.Debug:LogError(Object)
PlayerPrefsX:SetStringArray(String, String[]) (at Assets/PlayerPrefsX.cs:246)
Menu:OnGUI() (at Assets/Menu.cs:31)

Thanks

I guess you get the error because you’re trying to save the string array before it is filled with strings.

You are saving the array each time you set a new string. That means if you set
newArray[0] = "someString" in the first loop,
newArray[1] is still null … and you are trying to save that.

Save the array outside the for loop.