title: It seems xmlnode.Count doesnt exist, but why? Error : "xmlnode.Count = 'xmlnode.Count' threw an exception of type 'System.NullReferenceException'"
body: <p>I'm creating a program in which you enter an IP address and the program outputs a bunch of data about that IP. I'm using IPStack API to get this information. I've been trying it in XML but I'm aware that it can be done with JSON data too.</p>
  
  <p>I've looked at a bunch of tutorials which are using GeoIP ( Which has closed down). I've tried using very similar code but changed to work with IPstack instead of GeoIP.</p>
  
  <p>By using a breakpoint I see that when the line "For i = 0 To xmlnode.Count - 1" is read, the loop is jumped straight past, so in this instance I have changed it to +1. I am then given the following error</p>
  
  <blockquote>
    <p>xmlnode.Count = 'xmlnode.Count' threw an exception of type
    'System.NullReferenceException'</p>
  </blockquote>
  
  <pre><code>Private Sub geo()
  
      Dim xmlnode As XmlNodeList
  
      Dim IP As String = txtLookup.Text
  
      Dim APIKey As String = "?access_key=c48babe58dc723c552800c46cbd3c9c6&amp;format=1"
      Dim xmldoc As New XmlDocument
  
      Dim URL As String = "http://api.ipstack.com/" &amp; IP &amp; APIKey &amp; "&amp;output=xml"
  
      xmldoc.Load(URL)
  
      xmlnode = xmldoc.GetElementsByTagName("Response")
  
      For i = 0 To xmlnode.Count - 1 'This is the issue 
          xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
  
          Label2.Text = "Country Code : " &amp; xmlnode(i).ChildNodes.Item(1).InnerText.Trim()
  
          Label3.Text = "Country Name : " &amp; xmlnode(i).ChildNodes.Item(2).InnerText.Trim()
  
          Label4.Text = "Region Code : " &amp; xmlnode(i).ChildNodes.Item(3).InnerText.Trim()
  
          Label5.Text = "Region Name : " &amp; xmlnode(i).ChildNodes.Item(4).InnerText.Trim()
  
          Label6.Text = "City : " &amp; xmlnode(i).ChildNodes.Item(5).InnerText.Trim()
  
          Label7.Text = "Post Code : " &amp; xmlnode(i).ChildNodes.Item(6).InnerText.Trim()
  
          Label8.Text = "Latitude : " &amp; xmlnode(i).ChildNodes.Item(7).InnerText.Trim()
  
          Label9.Text = "Longitude : " &amp; xmlnode(i).ChildNodes.Item(8).InnerText.Trim()
  
      Next
  End Sub
  
  Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
      geo()
  End Sub
  </code></pre>