웹 사이트 HTML 소스 코드를 얻는 방법이 있습니다. 이 메서드는 간단한 Java 프로젝트에서 제대로 작동하지만 안드로이드 프로젝트 "indexoutofboundsexception 인덱스 0 크기 0"예외가 발생합니다.html 소스 코드 받기 : 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이 일치한다 : 어떤 도움
http://stackoverflow.com/questions/18285981/read-php-page-content-from-android-using-eclipse/18286023#18286023 –
@AmitPrajapati : 그 링크에 언급 된 해결책은 나에게도 동일한 예외를 제공합니다. !! !! –