开发者

SAX parser crashes with "Permission Denied" exception message when retrieving google weather XML

I'm trying to get the current temperature via google weather with SAX Parser but I get a "permission denied" exception message when I try to get data:

Code:

/* Get what user typed to the EditText. */

String cityParamString = ((EditText) findViewById(R.id.edit_input)).getText().toString();

String queryString = "http://www.google.com/ig/api?weather="+ cityParamString;

/* Replace blanks with HTML-Equivalent. */

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 */

GoogleWeatherHandler gwh = new GoogleWeatherHandler();

xr.setContentHandler(gwh);

/* Parse the xml-data our URL-call returned. */

xr.parse(new InputSource(url.openStream())); <---- THIS CRASHES WITH PERMISION DENIED EXCEPTION MESSAGE

The url seems to be fine, but url.openstream doesn't work.


You need to add uses internet permission to your android manifest

<uses-permission android:name="android.permission.INTERNET" />

Been there done that :), been super frustrated


Google maps is currently down in some parts of the world (if not all of it). Check Twitter for more info. There've been quite a few tweets in last few minutes.


As message suggests, HTTP request itself failed; nothing to do with XML parsing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜