Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NullReferenceException was unhandled

Status
Not open for further replies.

tookerello

Programmer
May 5, 2010
3
IE
Hi could somebody please help me with this as i have been trying to fix it for hours!!!
I keep receving the "NullReferenceException was unhandled " message in the line starting with cond.Town=xmlConditions.........


public static Conditions GetCurrentConditions(string location)
{
Conditions c;
c = null;
c = new Conditions();

c.GetCurrentConditions();

XmlDocument xmlConditions = new XmlDocument();
xmlConditions.Load(string.Format(" location));
if (xmlConditions.SelectSingleNode("xml_api_reply/weather/problem_cause") != null)
{
c = null;
}
else
{
Conditions cond = new Conditions();
cond.Town = xmlConditions.SelectSingleNode("/xml_api_reply/weather/forecast_information/city").Attributes["data"].InnerText;
cond.Condition = xmlConditions.SelectSingleNode("/xml_api_reply/weather/current_conditions/condition").Attributes["data"].InnerText;
cond.TempC = xmlConditions.SelectSingleNode("/xml_api_reply/weather/current_conditions/temp_c").Attributes["data"].InnerText;
cond.TempF = xmlConditions.SelectSingleNode("/xml_api_reply/weather/current_conditions/temp_f").Attributes["data"].InnerText;
cond.Humidity = xmlConditions.SelectSingleNode("/xml_api_reply/weather/current_conditions/humidity").Attributes["data"].InnerText;
cond.Wind = xmlConditions.SelectSingleNode("/xml_api_reply/weather/current_conditions/wind_condition").Attributes["data"].InnerText;

}

return c;
}
 
the path to city is different than the other xpath queries. are you sure all your paths are correct? if the node doesn't exist the method will return null. hence the null reference exception.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top