System.NuReferenceException: 'Object was set with an object made.' how to fix?

Zaug 306 Reputation points
2021-07-17T15:06:45.967+00:00

string metinok;
metinok = mainwindowtest.Text;
int konumok = -1;
string kelimeok = "=>";

            konumok = metinok.IndexOf(kelimeok, konumok + 1);
            mainwindowtest.Focus();
            if (konumok != -1)
            {
                if (runGame == true)
                {
                }
            }

I do not know what to say. it wasn't just being young, now this error pops up (in the title)

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,906 questions
{count} votes

Accepted answer
  1. Timon Yang-MSFT 9,591 Reputation points
    2021-07-21T01:29:36.03+00:00

    The reason for the problem is here:

            public MainWindow()  
            {  
                ZaugLanguage();  
                InitializeComponent();  
            }  
    

    We need to put the InitializeComponent method above the ZaugLanguage method.

    We can know from the name that this method is used to initialize the component. If the component has not been initialized, then of course a NuReferenceException will appear when we try to call it.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.