Question

I already know how to read a xml file from local storage. But now I would like to get the news from Yahoo! [link: http://hk.news.yahoo.com/rss/hong-kong ]

I use the code as below but it returns error, what is wrong?!?!

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();

The error log is :

05-22 14:34:25.696: E/RSS(24465): java.net.ConnectException: failed to connect to hk.news.yahoo.com/2406:2000:ac:8::c:9102 (port 80): connect failed: EHOSTUNREACH (No route to host)

THANKS!!

Was it helpful?

Solution

Check you Application internet permission in android Androidmenifest.xml.

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

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top