首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取html源代码: indexoutofboundsexception异常索引0大小0

获取html源代码: indexoutofboundsexception异常索引0大小0
EN

Stack Overflow用户
提问于 2013-08-25 20:30:38
回答 1查看 215关注 0票数 0

有一个方法,我正在用来获得一个网站的html源代码。这个方法在一个简单的java项目中工作得很好,但是在android项目中,"indexoutofboundsexception index 0 size 0“是错误的。

方法和日志包括:

代码语言:javascript
复制
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()));

谢谢你的帮助

EN

回答 1

Stack Overflow用户

发布于 2013-08-25 20:53:05

如果问题仍然存在,我的建议是使用Vector对象作为第二个参数来设置属性。从JSP中检索Vector,并从Vector对象中提取数据。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18428999

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档