Home c# Everything initialized .. an error occurs: Object reference does not point to...

Everything initialized .. an error occurs: Object reference does not point to an object instance

Author

Date

Category


Answer 1, authority 100%

If this is all the code, then this line (as well as subsequent ones)

gridToXml [i] .Key = dataGridView1.Rows [i] .Cells ["Key"]. Value.ToString ();

tries to set the Key property of the object in gridToXml [i] to the value to the right of the equal sign. At this point, of course, there is nothing in gridToXml [i] but null , because first, the object must be initialized and placed in gridToXml [i] :

for (int i = 0; i & lt; gridToXml.Count (); i ++)
  {
    gridToXml [i] = new ClassVivod ();
    ...

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions