How do you change the text of a button in Windows Phone 7 and C#? NullPointer Exception too, if I am doing the changing of the button text right, what is the problem?
public void CreateWords(Word[] theWords)
{
listOfWords = new Button[theWords.Length]; //Button Array
textBlock1.Text = theWords[0].getWord(); //Totally Works
for (int i = 0; i < theWords.Length; i++)
{
listOfWords[i].Content = theWords[0].getWord(); //NullPointer Exception
}
for (int i = 0; i < theWords.Length; i++)
{
stackWords.Children.Add(listOfWords[i]);
}
}
You’re getting the
NullReferenceExceptionbecause, while you have created the new Button array, you haven’t initialized any of the elements of that array (each element is still null).