none
Null Exepction Error with RSS Feed RRS feed

  • Question

  • Hello,

    I was able to fix the errors I had with the 403 forbidden. But now, it keeps throwing a null expection error for no reason. Heres the code:

    Timer1.Interval = 60000
            Dim doc As New XmlDocument
    
            Dim WxData As String = My.Settings.NWS_Alert
    
            Dim request As HttpWebRequest = DirectCast(WebRequest.Create(WxData), HttpWebRequest)
    
            request.Method = "GET"
            request.ContentType = "application/x-www-form-urlencoded"
            request.UserAgent = "NWIDC_Digital_HD10_Thunder/v1.0 (http://www.austinlandweather.com; myemailaddress)"
            request.Accept = "Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
    
            Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
            Dim resStream As Stream = response.GetResponseStream()
    
            doc.Load(resStream)
    
            If WXData <> LastWXData Then
                LastWXData = WXData
                ListBox1.Items.Clear()
                ListBox1.Enabled = False
                WXDict.Clear()
                Dim TitleList As XmlNodeList = XmlDoc.GetElementsByTagName("title")
                Dim SummaryList As XmlNodeList = XmlDoc.GetElementsByTagName("summary")
                For i = 1 To TitleList.Count - 1
                    WXDict.Add(TitleList(i).InnerText, SummaryList(i - 1).InnerText)
                Next
                TickerText.Text = SummaryList(0).InnerText
                ListBox1.Items.AddRange(WXDict.Keys.ToArray)
                ListBox1.Enabled = True
                ListBox1.SelectedIndex = 0
            End If
        End Sub
        Dim LastWXData As String = ""

    The error occurs at the code:

    TickerText.Text = SummaryList(0).InnerText
    Why is it doing this and how can this be corrected?
    Friday, March 24, 2017 4:01 PM

All replies

  • Hi

    Suggest: ensure in Debug mode. Put the word 'Stop' on the line after your error line. Start. When reaches the Stop, examine the SummaryList (looks like it may be empty.)


    Regards Les, Livingston, Scotland

    Friday, March 24, 2017 4:32 PM
  • Leshay, so if I put stop, what should that do?

    Here is the exepction details.

    System.NullReferenceException was unhandled
      HResult=-2147467261
      Message=Object reference not set to an instance of an object.
      Source=NWIDC Digital HD10 Thunder
      StackTrace:
           at NWIDC_Digital_HD10_Thunder.Main_Graphics.Timer11_Tick(Object sender, EventArgs e) in C:\Users\Austin\Documents\Visual Studio 2015\Projects\NWIDC Digital HD10 Thunder\NWIDC Digital HD10 Thunder\Main_Graphics.vb:line 990
           at System.Windows.Forms.Timer.OnTick(EventArgs e)
           at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
           at NWIDC_Digital_HD10_Thunder.My.MyApplication.Main(String[] Args) in :line 81
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
           at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
           at System.Activator.CreateInstance(ActivationContext activationContext)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: 

    Friday, March 24, 2017 4:43 PM
  • Hi

    Did you try running the project with the 'Stop' line added? If so, then presumably it5 didn't reach that line - so, move the Stop to the line above

    Stop

    TickerText.Text = SummaryList(0).InnerText

    and try running - when it stops then (in Debug mode) put cursor over SummaryList and see if it contains anything.


    Regards Les, Livingston, Scotland


    • Edited by leshay Friday, March 24, 2017 5:41 PM
    Friday, March 24, 2017 5:40 PM
  • It crashed it when it came to the stop.
    Friday, March 24, 2017 6:03 PM
  • Hi

    What do you mean by 'crashed'? Was the application showing as running in the Toolbar when it reached the Stop line?


    Regards Les, Livingston, Scotland

    Friday, March 24, 2017 6:09 PM
  • In version 2017 they  have ruined in my opinion the way debugging could easily be done. 

    However, if you have no version 2017 but an earlier one you can right click on a line and set a breakpoint 

    Do that on the line

    Dim SummaryList As XmlNodeList = XmlDoc.GetElementsByTagName("summary")

    After that you Run with F10 or start and when it stops there you click on F10, with one step you can right click on SummaryList and choose Quick Watch. Now you can see everything. 

    In version 2017 they have removed those debugging possibility for whatever reason. But you can still set a breakpoint with F9. 

    If you want the easy handling of breakpoints back in 2017 it is possible using the Customize Options. I tried it but I was not yet able to do that.

    If I'm happy with this change, I think you know the answer yourself.


    Success
    Cor


    Friday, March 24, 2017 6:12 PM
  • Cor, I will try that and see what happens. Now, looking at the code, how can I correct it to make sure that when the RSS feed is accessed, the user-agent is their and the code does what it is designed to do. The origional code for the weather alert ticker was given to me by Mr. Monkeyboy in a previous question I asked a while back but the NWS changed something and it caused problems with it since January of 2017.
    Friday, March 24, 2017 6:17 PM
  • I know the code that worked before was given to be by Mr. Monkeyboy. The NWS requires this line to be added in the Http Request:

    request.UserAgent = "NWIDC_Digital_HD10_Thunder/v1.0 (mywebsite; myemailaddress)"

    How can I add that into the request of this code:

    Timer1.Interval = 60000
            Using WB As New WebClient
                Try
                    Dim WXData As String = WB.DownloadString(The URL of the RSS Feed)
                    If WXData <> LastWXData Then
                        LastWXData = WXData
                        ListBox1.Items.Clear()
                        ListBox1.Enabled = False
                        WXDict.Clear()
                        XmlDoc.LoadXml(WXData)
                        Dim TitleList As XmlNodeList = XmlDoc.GetElementsByTagName("title")
                        Dim SummaryList As XmlNodeList = XmlDoc.GetElementsByTagName("summary")
                        For i = 1 To TitleList.Count - 1
                            WXDict.Add(TitleList(i).InnerText, SummaryList(i - 1).InnerText)
                        Next
                        Label6.Text = summaryList(0).InnerText
                        ListBox1.Items.AddRange(WXDict.Keys.ToArray)
                        ListBox1.Enabled = True
                        ListBox1.SelectedIndex = 0
                    End If
                Catch ex As Exception
                End Try
            End Using

    Friday, March 24, 2017 7:43 PM
  • Yea but John (mr Monkeyboy) did do that on data as it was then, you have to investigate what it returns currently. 

    Otherwise you can also contact those who are responsible for the RSS feed.

    There is not one law which tells them they are not allowed to change that. 


    Success
    Cor

    Friday, March 24, 2017 7:54 PM
  • Well, the RSS Feed is owned by the National Weather Service which is owned by the US Gov.
    Friday, March 24, 2017 8:03 PM
  • Well, the RSS Feed is owned by the National Weather Service which is owned by the US Gov.

    I can contact John, but without asking to him, I know what he would write. 


    Success
    Cor


    Friday, March 24, 2017 8:40 PM