Object Reference Not Set To An Instance of an Object: .Get returned Nothing

  • Thread starter Thread starter Austin Althouse
  • Start date Start date
A

Austin Althouse

Guest
Hello,

I have a weather application that I am having issued getting forecasts. I am getting the following Null Reference Exception:

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=AWNHD Weather Broadcast Engine
StackTrace:
at AWNHD_Weather_Broadcast_Engine.WxDisplay.NWS_Forecast() in C:\Users\aawea\source\repos\AWNHD Weather Broadcast Engine\WxDisplay.vb:line 199

Here is the code in the form:

Using WB As New WebClient
Try
WB.Headers.Add("User-Agent", "AWN WIGC Engine HD/v1.0 (http://www.austinlandweather.com; EMAIL")
Dim ForecastData As String = WB.DownloadString($"https://api.weather.gov/zones/forecast/{My.Settings.NWS_Wx_Forecast}/forecast")

Dim weather As WeatherData = JsonConvert.DeserializeObject(Of WeatherData)(ForecastData)

Dim period As Period = New Period

Period1Forecast.Text = weather.periods(0).detailedForecast
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using





The exception says AWNHD_Weather_Broadcast_Engine.WeatherData.periods.get returned Nothing. Here is the code for WeatherData.periods:

Public Class Period
Public Property number As Integer
Public Property name As String
Public Property detailedForecast As String
End Class

My application is downloading the string for the json feed but is failing to deserialize or is failing to take the information and display it in a label. I tried a textbox and I get the same result.

This code ran smoothly for several months and randomly quit working one day. I am running VS 2019. How can that error be corrected and why is it occurring?

Continue reading...
 
Back
Top