0

There is a method that i am using to get a website html source code. this method works fine in a simple java project, but in an android project "indexoutofboundsexception index 0 size 0" exeption accurs.

the method and the log included:

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;

}

enter image description here

the Exeption is in this line:

in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));

Thanks for any help

4

1 回答 1

0

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

于 2013-08-25T12:53:04.970 回答