-2

I want to change a label in my c# .net wpf program but im getting an error nobody else gets.

i've tried different text boxes and looked up tutorials they all say to do this but it doesn't work ;(

namespace p1_start
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            XmlDocument data = new XmlDocument();
            data.Load("sata.xml");
            username.Content = "test"; //--error 

            InitializeComponent();
        }
    }
}

System.NullReferenceException: 'Object reference not set to an instance of an object.'

Potoo
  • 13
  • 5

1 Answers1

-1

This is because username hasn't been initialized yet. Call InitializeComponent() before you try to set the content.