2013-04-21 77 views
0

我是新的android和我試圖從一個網站使用jsoup獲取數據,但是當我執行get()方法沒有反應。這裏是我的代碼:無法連接到使用Jsoup的網站android

static final String BLOG_URL = "http://xjaphx.wordpress.com/"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_html_parser); 
    // Show the Up button in the action bar. 
    setupActionBar(); 


     // process 
    new DownloadFilesTask().execute(); 
} 

私有類DownloadFilesTask擴展的AsyncTask {

 String result = ""; 
    @Override 
    protected String doInBackground(Void... params) { 

      // get html document structure 
      Document document=null; 
      try { 
       document = Jsoup.connect(BLOG_URL).get(); 

      // selector query 
      Elements nodeBlogStats = document.select("div#blog-stats ul li"); 
      // check results 
      if(nodeBlogStats.size() > 0) { 
       // get value 
       result = nodeBlogStats.get(0).text(); 
      } 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      // return 


      return null; 
    } 


    protected void onPostExecute() 
    { 

    TextView article = (TextView)findViewById(R.id.textView1); 

    article.setText(result); 

}

} 

這是我的logcat日誌:

04-21 12:13:24.458: W/System.err(4501): java.net.UnknownHostException: xjaphx.wordpress.com 
04-21 12:13:24.458: W/System.err(4501):  at java.net.InetAddress.lookupHostByName(InetAddress.java:506) 
04-21 12:13:24.458: W/System.err(4501):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294) 
04-21 12:13:24.458: W/System.err(4501):  at java.net.InetAddress.getAllByName(InetAddress.java:256) 
04-21 12:13:24.458: W/System.err(4501):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69) 
04-21 12:13:24.458: W/System.err(4501):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48) 
04-21 12:13:24.458: W/System.err(4501):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322) 
04-21 12:13:24.458: W/System.err(4501):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89) 
04-21 12:13:24.458: W/System.err(4501):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285) 
04-21 12:13:24.458: W/System.err(4501):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267) 
04-21 12:13:24.458: W/System.err(4501):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205) 
04-21 12:13:24.458: W/System.err(4501):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:425) 
04-21 12:13:24.458: W/System.err(4501):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410) 
04-21 12:13:24.458: W/System.err(4501):  at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164) 
04-21 12:13:24.458: W/System.err(4501):  at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153) 
04-21 12:13:24.458: W/System.err(4501):  at pdm.ebudget.HtmlParser$DownloadFilesTask.doInBackground(HtmlParser.java:158) 
04-21 12:13:24.458: W/System.err(4501):  at pdm.ebudget.HtmlParser$DownloadFilesTask.doInBackground(HtmlParser.java:1) 
04-21 12:13:24.468: D/KeyguardViewMediator(1484): setHidden false 
04-21 12:13:24.468: W/System.err(4501):  at android.os.AsyncTask$2.call(AsyncTask.java:185) 
04-21 12:13:24.478: W/System.err(4501):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
04-21 12:13:24.478: W/System.err(4501):  at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
04-21 12:13:24.478: W/System.err(4501):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
04-21 12:13:24.478: W/System.err(4501):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
04-21 12:13:24.478: W/System.err(4501):  at java.lang.Thread.run(Thread.java:1019) 

我已經把在我的清單中,互聯網訪問線:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 

回答

1

我的壞,沒有互聯網連接在我的android終端上線^^,對不起!