Using java Syntax Highlighting
- package com.android.weatherapp;
- import java.net.URL;
- import javax.xml.parsers.SAXParser;
- import javax.xml.parsers.SAXParserFactory;
- import org.xml.sax.InputSource;
- import org.xml.sax.XMLReader;
- import android.app.Activity;
- import android.os.Bundle;
- import android.util.Log;
- import android.widget.TextView;
- public class weatherapp extends Activity {
- private final String MY_DEBUG_TAG = "AUWeather";
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- /* Create a new TextView to display the parsing result later. */
- TextView tv = new TextView(this);
- try
- {
- /* Create a URL we want to load some xml-data from. */
- String queryString = "http://weather.yahooapis.com/forecastrss?p=36832";
- /* Replace blanks with HTML-Equivalent. */
- URL url = new URL(queryString.replace(" ", "%20"));
- /* Get a SAXParser from the SAXPArserFactory. */
- SAXParserFactory spf = SAXParserFactory.newInstance();
- SAXParser sp = spf.newSAXParser();
- /* Get the XMLReader of the SAXParser we created. */
- XMLReader xr = sp.getXMLReader();
- /* Create a new ContentHandler and apply it to the XML-Reader */
- WeatherHandler myWeatherHandler = new WeatherHandler();
- xr.setContentHandler(myWeatherHandler);
- /* Parse the xml-data from our URL. */
- xr.parse(new InputSource(url.openStream()));
- /* Parsing has finished. */
- String myText = myWeatherHandler.getInfo();
- tv.setText(myText);
- } catch (Exception e)
- {
- tv.setText("Error: " + e.getMessage());
- Log.e(MY_DEBUG_TAG, "WeatherQueryError", e);
- }
- /* Display the TextView. */
- setContentView(tv);
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
Dumps out this:
- Code: Select all
10-07 22:55:45.664: ERROR/AUWeather(163): WeatherQueryError
10-07 22:55:45.664: ERROR/AUWeather(163): java.net.UnknownHostException: Host is unresolved: weather.yahooapis.com:80
10-07 22:55:45.664: ERROR/AUWeather(163): at java.net.Socket.connect(Socket.java:928)
10-07 22:55:45.664: ERROR/AUWeather(163): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:61)
10-07 22:55:45.664: ERROR/AUWeather(163): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
10-07 22:55:45.664: ERROR/AUWeather(163): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
10-07 22:55:45.664: ERROR/AUWeather(163): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:800)
10-07 22:55:45.664: ERROR/AUWeather(163): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:786)
10-07 22:55:45.664: ERROR/AUWeather(163): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1030)
10-07 22:55:45.664: ERROR/AUWeather(163): at java.net.URL.openStream(URL.java:664)
10-07 22:55:45.664: ERROR/AUWeather(163): at com.android.weatherapp.weatherapp.onCreate(weatherapp.java:45)
10-07 22:55:45.664: ERROR/AUWeather(163): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122)
10-07 22:55:45.664: ERROR/AUWeather(163): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2103)
10-07 22:55:45.664: ERROR/AUWeather(163): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2156)
10-07 22:55:45.664: ERROR/AUWeather(163): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
10-07 22:55:45.664: ERROR/AUWeather(163): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
10-07 22:55:45.664: ERROR/AUWeather(163): at android.os.Handler.dispatchMessage(Handler.java:88)
10-07 22:55:45.664: ERROR/AUWeather(163): at android.os.Looper.loop(Looper.java:123)
10-07 22:55:45.664: ERROR/AUWeather(163): at android.app.ActivityThread.main(ActivityThread.java:3742)
10-07 22:55:45.664: ERROR/AUWeather(163): at java.lang.reflect.Method.invokeNative(Native Method)
10-07 22:55:45.664: ERROR/AUWeather(163): at java.lang.reflect.Method.invoke(Method.java:515)
10-07 22:55:45.664: ERROR/AUWeather(163): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
10-07 22:55:45.664: ERROR/AUWeather(163): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
10-07 22:55:45.664: ERROR/AUWeather(163): at dalvik.system.NativeStart.main(Native Method)
And I have no idea why. Its almost straight from examples and the URL checks out. I have no proxy either. Any ideas? The internet permission is set as well.


