当我使用下面的url在android上的地图上绘制路线时:
StringBuilder urlString = new StringBuilder();
urlString.append("http://maps.google.com/maps?f=d&hl=en");
urlString.append("&saddr=");
urlString.append(src);
urlString.append("&daddr=");// to
urlString.append(dest);
urlString.append("&ie=UTF8&0&om=0&output=kml");
调用urlConnection.getInputStream时抛出异常。
HttpURLConnection urlConnection=(HttpURLConnection)url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(urlConnection.getInputStream());
新守则:
Document doc=null;
try
{
String url = getUrl(p, q);
DocumentBuilderFactory dbfAdd = DocumentBuilderFactory.newInstance();
DocumentBuilder dbAdd = dbfAdd.newDocumentBuilder();
doc = dbAdd.parse(url.toString());
答案 0 :(得分:0)
IIRC Android的XML文档解析器无法处理阻塞的InputStream
。最好使用为你做下载的parse()版本,即:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(urlString.toString());