有一个方法,我正在用来获得一个网站的html源代码。这个方法在一个简单的java项目中工作得很好,但是在android项目中,"indexoutofboundsexception index 0 size 0“是错误的。
方法和日志包括:
private String getUrlSource(String url_str) throws Exception {
String htmlText="";
BufferedReader in = null;
try {
URL url = new URL(url_str);
URLConnection spoof = url.openConnection();
spoof.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
htmlText=htmlText + inputLine + "\n";
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null)
in.close();
}
Log.d("getURL", "done");
return htmlText;
}

Exeption在下面这行代码中:
in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
谢谢你的帮助
发布于 2013-08-25 20:53:05
如果问题仍然存在,我的建议是使用Vector对象作为第二个参数来设置属性。从JSP中检索Vector,并从Vector对象中提取数据。
https://stackoverflow.com/questions/18428999
复制相似问题