2013-05-22 42 views
0

我已經知道如何從本地存儲讀取xml文件。但是現在我想從雅虎那裏得到消息。 [鏈接:http://hk.news.yahoo.com/rss/hong-kong]Android RSS無法從鏈接下載xml文件

我使用下面的代碼,但它返回錯誤,出了什麼問題?!?!

String source = "http://hk.news.yahoo.com/rss/hong-kong"; 
URL url = new URL(source); 
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); 
urlConnection.setRequestMethod("GET"); 
urlConnection.connect(); 

InputStreamReader in = new InputStreamReader(urlConnection.getInputStream()); 
BufferedReader br = new BufferedReader(in); 
String result = br.readLine(); 
Log.i(tag, "GET success: " + result); 

br.close(); 
in.close(); 

錯誤日誌是:

05-22 14:34:25.696:E/RSS(24465):java.net.ConnectException:未能連接到hk.news.yahoo.com/ 2406:2000:ac:8 :: c:9102(端口80):連接失敗:EHOSTUNREACH(沒有路由到主機)

感謝!

回答

0

在Android Androidmenifest.xml中檢查應用程序的Internet權限。

​​

感謝

+0

已經得到了許可..... –

+0

http://stackoverflow.com/questions/12522396/tcp-ip-client-ehostunreach-no-route-to-host –

+0

對不起....我發現它是我用於測試的Android設備沒有鏈接到互聯網....謝謝... –