Hallo Community,
mein Problem ist folgendes ich möchte Yahoo's Wetter Webservice benutzten, soweit so gut. Ich habe mit dem InputStream die RSS/XML-Datei erhalten und mag nun Werte auslesen aber komischerweise erhalte ich immer eine NullpointerException?! Ich habe alles durchdebugged und Sysout geprüft alles regulär...ich finds sehr komisch könntet ihr mal'n blick drüber werfen?
Und hier die erhaltene RSS/XML Datei:
[XML]<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
<title>Yahoo! Weather - Sunnyvale, CA</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
<description>Yahoo! Weather for Sunnyvale, CA</description>
<language>en-us</language>
<lastBuildDate>Sat, 19 Mar 2011 3:56 pm PDT</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Sunnyvale" region="CA" country="United States"/>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
<yweather:wind chill="51" direction="150" speed="10" />
<yweather:atmosphere humidity="" visibility="7" pressure="29.8" rising="0" />
<yweather:astronomy sunrise="7:12 am" sunset="7:19 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url>
</image>
<item>
<title>Conditions for Sunnyvale, CA at 3:56 pm PDT</title>
<geo:lat>37.37</geo:lat>
<geo:long>-122.04</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
<pubDate>Sat, 19 Mar 2011 3:56 pm PDT</pubDate>
<yweather:condition text="Light Rain" code="11" temp="51" date="Sat, 19 Mar 2011 3:56 pm PDT" />
<description><![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/11.gif"/><br />
<b>Current Conditions:</b><br />
Light Rain, 51 F<BR />
<BR /><b>Forecast:</b><BR />
Sat - Rain/Wind. High: 53 Low: 50<br />
Sun - Rain. High: 56 Low: 45<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]></description>
<yweather:forecast day="Sat" date="19 Mar 2011" low="50" high="53" text="Rain/Wind" code="12" />
<yweather:forecast day="Sun" date="20 Mar 2011" low="45" high="56" text="Rain" code="12" />
<guid isPermaLink="false">USCA1116_2011_03_19_15_56_PDT</guid>
</item>
</channel>
</rss>
<!-- api1.weather.ch1.yahoo.com compressed/chunked Sat Mar 19 17:06:19 PDT 2011 -->
[/XML]
Ich find den Fehler nicht...
mein Problem ist folgendes ich möchte Yahoo's Wetter Webservice benutzten, soweit so gut. Ich habe mit dem InputStream die RSS/XML-Datei erhalten und mag nun Werte auslesen aber komischerweise erhalte ich immer eine NullpointerException?! Ich habe alles durchdebugged und Sysout geprüft alles regulär...ich finds sehr komisch könntet ihr mal'n blick drüber werfen?
Java:
public void getRequestData(Element root) {
Element dataElement = root.getChild("channel");
/* general info */
title = dataElement.getChild("title").getValue();
description = dataElement.getChild("description").getValue();
/* location info */
locationCity = dataElement.getChild("yweather:location").getAttribute("city").getValue();
System.out.println(locationCity);
locationRegion = dataElement.getChild("yweather:location").getAttribute("region").getValue();
locationCountry = dataElement.getChild("yweather:location").getAttribute("country").getValue();
/* unit info */
unitTemperature = dataElement.getChild("yweather:units").getAttribute("temperature").getValue();
unitDistance = dataElement.getChild("yweather:units").getAttribute("distance").getValue();
unitPressure = dataElement.getChild("yweather:units").getAttribute("pressure").getValue();
unitSpeed = dataElement.getChild("yweather:units").getAttribute("speed").getValue();
/* wind info */
windChill = dataElement.getChild("yweather:wind").getAttribute("chill").getValue();
windDirection = dataElement.getChild("yweather:wind").getAttribute("direction").getValue();
windSpeed = dataElement.getChild("yweather:wind").getAttribute("speed").getValue();
/* atmosphere info */
atmosphereHumidity = dataElement.getChild("yweather:atmosphere").getAttribute("humidity").getValue();//feuchtigkeit
atmosphereVisibility = dataElement.getChild("yweather:atmosphere").getAttribute("visibility").getValue();
atmospherePressure = dataElement.getChild("yweather:atmosphere").getAttribute("pressure").getValue();
atmosphereRising = dataElement.getChild("yweather:atmosphere").getAttribute("rising").getValue();
astronomySunrise = dataElement.getChild("yweather:astronomy").getAttribute("sunrise").getValue();
astronomySunset = dataElement.getChild("yweather:astronomy").getAttribute("sunset").getValue();
itemGeoLAT = dataElement.getChild("item").getChild("geo:lat").getValue();
itemGeoLONG = dataElement.getChild("item").getChild("geo:long").getValue();
itemPubDate = dataElement.getChild("item").getChild("pubDate").getValue();
itemConditionsCode = dataElement.getChild("item").getChild("yweather:condition").getAttribute("code").getValue();
itemConditionsTemperature = dataElement.getChild("item").getChild("yweather:condition").getAttribute("temp").getValue();
itemConditionsDate = dataElement.getChild("item").getChild("yweather:condition").getAttribute("date").getValue();
// Element foreCast = dataElement.getChild("item").getChild("yweather:forecast");
}
Und hier die erhaltene RSS/XML Datei:
[XML]<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
<title>Yahoo! Weather - Sunnyvale, CA</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
<description>Yahoo! Weather for Sunnyvale, CA</description>
<language>en-us</language>
<lastBuildDate>Sat, 19 Mar 2011 3:56 pm PDT</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Sunnyvale" region="CA" country="United States"/>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
<yweather:wind chill="51" direction="150" speed="10" />
<yweather:atmosphere humidity="" visibility="7" pressure="29.8" rising="0" />
<yweather:astronomy sunrise="7:12 am" sunset="7:19 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url>
</image>
<item>
<title>Conditions for Sunnyvale, CA at 3:56 pm PDT</title>
<geo:lat>37.37</geo:lat>
<geo:long>-122.04</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
<pubDate>Sat, 19 Mar 2011 3:56 pm PDT</pubDate>
<yweather:condition text="Light Rain" code="11" temp="51" date="Sat, 19 Mar 2011 3:56 pm PDT" />
<description><![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/11.gif"/><br />
<b>Current Conditions:</b><br />
Light Rain, 51 F<BR />
<BR /><b>Forecast:</b><BR />
Sat - Rain/Wind. High: 53 Low: 50<br />
Sun - Rain. High: 56 Low: 45<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]></description>
<yweather:forecast day="Sat" date="19 Mar 2011" low="50" high="53" text="Rain/Wind" code="12" />
<yweather:forecast day="Sun" date="20 Mar 2011" low="45" high="56" text="Rain" code="12" />
<guid isPermaLink="false">USCA1116_2011_03_19_15_56_PDT</guid>
</item>
</channel>
</rss>
<!-- api1.weather.ch1.yahoo.com compressed/chunked Sat Mar 19 17:06:19 PDT 2011 -->
[/XML]
Ich find den Fehler nicht...