- Home /
Question by
Le-Capitaine · Apr 09, 2014 at 08:50 AM ·
c#nullreferenceexceptionarrays2d array
[Solved] Actually totally explainable NRE with 2D array
edit: As it turned out, the NRE was because I was trying to access the values' property .text
at the same time as I was initialising it, which can't be done. The problem was solved by converting the GUIText table to a string table.
I really just don't know. Everything seems declared and initialised as it should be. Has it got anything to do with my starting my arrays at 1 instead of 0?
private GUIText[,] keyValues;
private GUIText keyCursor;
private int controlsX;
private int controlsY;
void Start () {
keyValues = new GUIText[3, 9];
keyValues [1,1].text = controller.p1Button8.ToString ();
keyValues [1,2].text = controller.p1Button2.ToString ();
keyValues [1,3].text = controller.p1Button4.ToString ();
keyValues [1,4].text = controller.p1Button6.ToString ();
keyValues [1,5].text = controller.p1ButtonA.ToString ();
keyValues [1,6].text = controller.p1ButtonD.ToString ();
keyValues [1,7].text = controller.p1ButtonPause.ToString ();
keyValues [1,8].text = "";
keyValues [2,1].text = controller.p2Button8.ToString ();
keyValues [2,2].text = controller.p2Button2.ToString ();
keyValues [2,3].text = controller.p2Button4.ToString ();
keyValues [2,4].text = controller.p2Button6.ToString ();
keyValues [2,5].text = controller.p2ButtonA.ToString ();
keyValues [2,6].text = controller.p2ButtonD.ToString ();
keyValues [2,7].text = controller.p2ButtonPause.ToString ();
keyValues [2,8].text = "";
controlsX = 1;
controlsY = 1;
}
void Update () {
keyCursor.text = keyValues [controlsX,controlsY].text;
}
Comment
Your answer
Follow this Question
Related Questions
Null reference when accessing GameObject in the Array(C#) 1 Answer
NullReference when accessing GameObject in array (C#) 1 Answer
MergeSort function acting strange 0 Answers
Editor forgets elements of array after saving changes to code 0 Answers
C#: Arrays inside Arrays create a NullReferenceExeption? 1 Answer