2011-06-10 98 views
0

使用上JSoup網站上的導遊,我寫了下面的代碼:的Android JSoup連接問題

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    try { 
     Document doc = Jsoup.connect("http://google.com").get(); 
     Elements links = doc.getElementsByTag("a"); 
     for(Element ele : links){ 
      Log.i("Menu", ele.text()); 
     } 
    } catch (IOException e) { 

    } 
    setContentView(R.layout.main); 
} 

我在清單文件中添加Internet權限,但它不斷拋出IOException異常!

+0

哪一個呢?請分享整個異常消息和堆棧跟蹤。 – BalusC 2011-06-10 20:02:51

回答

2

我測試了你的代碼,它應該可以正常工作......我想象你的許可被放在了錯誤的地方。它進入您的應用程序定義之前,在你的清單:

這裏是我的清單的前幾行運行代碼:

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

<application android:icon="@drawable/icon" android:label="@string/app_name">