2013-08-25 3 views
0

웹 사이트 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; 

} 

enter image description here

Exeption이 일치한다 : 어떤 도움

+0

http://stackoverflow.com/questions/18285981/read-php-page-content-from-android-using-eclipse/18286023#18286023 –

+0

@AmitPrajapati : 그 링크에 언급 된 해결책은 나에게도 동일한 예외를 제공합니다. !! !! –

답변

0

문제가 만약에

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

감사합니다 지속, 내 sugge stion is use 속성을 설정하는 두 번째 매개 변수 인 Vector 객체입니다. JSP에서 Vector를 추출하고 Vector 객체에서 데이터를 추출합니다.

+0

자세히 설명해 주시겠습니까? code.how 포함해야합니까? –

관련 문제