0

I am correctly Appending my string with a For loop and iterator It not working it errors on the AppendLine Method of the string builder.

   StringBuilder[] Certs;

   //Just Display read outs here
    var groups = from exp in main.Elements("Network")
                 where exp.Attribute("Nid").Value == IntializedNetworks[i].ToString()
                 select exp;
    foreach (string exp in groups)
    {
        for (int x = 0; x < IntializedPostStat.Count(); x++)
        {
            Certs = new StringBuilder[IntializedPostStat.Count()];
            int b = 0;
            IntializedPostStat[x] = exp.ToString();
            if (IntializedPostStat[i] != null)
            {
               Certs[x].Append("[Certificate]   " + IntializedPostStat[x].ToString());
               listBox1.Items.Add(Certs[x].ToString());
            }

            break;
        }
    }
John Saunders
  • 157,405
  • 24
  • 229
  • 388
shawn
  • 133
  • 1
  • 1
  • 12
  • so is your listview horizontally aligned or something? – Sam I am says Reinstate Monica Sep 10 '13 at 20:41
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Sep 10 '13 at 21:30
  • I changed the method, I am displaying the data in a listbox, except I am using an Stringbuilder array to add the array of string data in a string builder, then Append that data and display it in the list view. I am getting an error appending it but my loops are correct. – shawn Sep 10 '13 at 21:30
  • The thing is my string builder array is defined properly and initialized in size, My object is not null, The AppendLine method, seems to messing up for some reason if you look at my code you should be able to see, I can not see it, it builds just fine. – shawn Sep 10 '13 at 21:45

1 Answers1

1

You appear to be mixing your indexes, you are looping on x, but on this line you are indexing on i:

        if (IntializedPostStat[i] != null)
        {

Given that your indexes are out of sync it's not surprising that you are getting null reference exceptions.

ChrisF
  • 127,439
  • 29
  • 243
  • 315