2012-01-10 102 views
1

當我使用openStream()從Web服務解析XML,我得到的錯誤:錯誤:網址無法打開流

Can not open stream

我檢查的URL,它仍然工作。

URL url = new URL("http://uitbookshop.php0h.com/PHPService/findbyname.php?name=thu"); 
Log.d("search", "getXML::url "+url.toString()); 
InputStream iS; 
try { 
    iS = url.openStream(); 

    doc=db.parse(new InputSource(new InputStreamReader(iS, Charset.forName("utf-8")))); 
} catch (IOException e) { 
    Log.e("search", "Can not open stream"); 
} catch (SAXException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 
+1

建議在IOException異常catch塊刪除日誌,並使用'e.printStackTrace()'來獲取詳細的錯誤信息。 – idiottiger 2012-01-10 03:13:43

回答

6

你有適當的權限? 請確保您有以下權限添加到清單

android.permission.INTERNET 
+0

謝謝你,它的工作原理 – 2012-01-10 03:17:37