Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
LinkBack Thread Tools
Old January 28th, 2013, 03:04 AM   #1 (permalink)
New Member
Thread Author (OP)
Join Date: Jan 2013
Posts: 2
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default RSS Reader

I am new to android development.I tried this RSS Reader app using some blog.I couldn't figure out the errorin my code.Its showing ANR error.Please help !

package com.example.simplerssreader;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class SimpleRSSReaderActivity extends ListActivity
List headlines=new ArrayList();
List links=new ArrayList();

protected void onCreate(Bundle savedInstanceState)

ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, headlines);

new PostTask().execute("http://feeds.pcworld.com/pcworld/latestnews");


protected void onListItemClick(ListView l, View v, int position, long id)
Uri uri = Uri.parse((links.get(position)).toString());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);

private class PostTask extends AsyncTask<String, Integer, String>
protected void onPreExecute() {


protected String doInBackground(String... params)
String para=params[0];
try {

URL url = new URL(para);

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();

// We will get the XML from an input stream

xpp.setInput(url.openStream(), "UTF_8");

/* We will parse the XML content looking for the "<title>" tag which appears inside the "<item>" tag.

* However, we should take in consideration that the rss feed name also is enclosed in a "<title>" tag.

* As we know, every feed begins with these lines: "<channel><title>Feed_Name</title>...."

* so we should skip the "<title>" tag which is a child of "<channel>" tag,

* and take in consideration only "<title>" tag which is a child of "<item>"


* In order to achieve this, we will make use of a boolean variable.


boolean insideItem = false;

// Returns the type of current event: START_TAG, END_TAG, etc..

int eventType = xpp.getEventType();

while (eventType != XmlPullParser.END_DOCUMENT) {

if (eventType == XmlPullParser.START_TAG) {

if (xpp.getName().equalsIgnoreCase("item")) {

insideItem = true;

} else if (xpp.getName().equalsIgnoreCase("title")) {

if (insideItem)

headlines.add(xpp.nextText()); //extract the headline

} else if (xpp.getName().equalsIgnoreCase("link")) {

if (insideItem)

links.add(xpp.nextText()); //extract the link of article


}else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){



eventType = xpp.next(); //move to next element


} catch (MalformedURLException e) {


} catch (XmlPullParserException e) {


} catch (IOException e) {



return "DONE !";



protected void onProgressUpdate(Integer... values) {




protected void onPostExecute(String result) {





saurabh44 is offline  
Reply With Quote
sponsored links
rss reader

Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

All times are GMT -5. The time now is 11:19 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.