SAX parser crashes with “Permission Denied” exception message when retrieving google weather XML
我试图通过谷歌天气与SAX Parser获取当前温度,但当我尝试获取数据时,我收到"许可被拒绝"异常消息:
码:
/* 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
网址似乎很好,但url.openstream不起作用。
您需要为您的Android清单添加使用Internet权限
1 | <uses-permission android:name="android.permission.INTERNET" /> |
去过那里:),非常沮丧
正如消息所示,HTTP请求本身失败了; 与XML解析无关。
谷歌地图目前在世界某些地区(如果不是全部的话)下降。 查看Twitter以获取更多信息。 在过去的几分钟内发过了不少推文。