Parsing Rss feed in listview Android

In my android app I parse JSON code from website successfully. But when I tried to parse RSS feed (XML) from a website I get an error. Can you please help me to solve this.

public class FeedListActivity extends Activity { private ArrayList<FeedItem> feedList = null; private ProgressBar progressbar = null; private ListView feedListView = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_posts_list); progressbar = (ProgressBar) findViewById(; String url = ""; new DownloadFilesTask().execute(url); } public void updateList() { feedListView= (ListView) findViewById(; feedListView.setVisibility(View.VISIBLE); progressbar.setVisibility(View.GONE); feedListView.setAdapter(new CustomListAdapter(this, feedList)); feedListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> a, View v, int position, long id) { Object o = feedListView.getItemAtPosition(position); FeedItem newsData = (FeedItem) o; Intent intent = new Intent(FeedListActivity.this, FeedDetailsActivity.class); intent.putExtra("feed", newsData); startActivity(intent); } }); } private class DownloadFilesTask extends AsyncTask<String, Integer, Void> { @Override protected void onProgressUpdate(Integer... values) { } @Override protected void onPostExecute(Void result) { if (null != feedList) { updateList(); } } @Override protected Void doInBackground(String... params) { String url = params[0]; // getting JSON string from URL JSONObject json = getJSONFromUrl(url); //parsing json data parseJson(json); return null; } } public JSONObject getJSONFromUrl(String url) { InputStream is = null; JSONObject jObj = null; String json = null; // Making HTTP request try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); } // return JSON String return jObj; } public void parseJson(JSONObject json) { try { // parsing json object if (json.getString("status").equalsIgnoreCase("ok")) { JSONArray posts = json.getJSONArray("posts"); feedList = new ArrayList<FeedItem>(); for (int i = 0; i < posts.length(); i++) { JSONObject post = (JSONObject) posts.getJSONObject(i); FeedItem item = new FeedItem(); item.setTitle(post.getString("title")); item.setDate(post.getString("date")); item.setId(post.getString("id")); item.setUrl(post.getString("url")); item.setContent(post.getString("content")); JSONArray attachments = post.getJSONArray("attachments"); if (null != attachments && attachments.length() > 0) { JSONObject attachment = attachments.getJSONObject(0); if (attachment != null) item.setAttachmentUrl(attachment.getString("url")); } feedList.add(item); } } } catch (JSONException e) { e.printStackTrace(); } } }

Category:android Views:4 Time:2018-09-09

Related post

  • Android 3.0 Honeycomb problem in parsing RSS feed 2011-06-08

    I am trying to parse rss feed in honeycomb 3.0 but it gives error as follows. ERROR/AndroidNews::PullFeedParser(444): android.os.NetworkOnMainThreadException I tried same code in android lower version it works but it doesn't work in Honeycomb. Please

  • Trouble parsing RSS feed for android 2012-02-19

    OK, so i am trying to parse this feed for an android application: and i am doing it whit this code: protected List<GamestarFeedItem> doInBackground(Context... params) { context = params[0]; DocumentBuild

  • How to parse rss-feeds / xml in a shell script 2009-01-14

    I'd like to parse rss feeds and download podcasts on my ReadyNas which is running 24/7 anyway. So I'm thinking about having a shell script checking periodically the feeds and spawning wget to download the files. What is the best way to do the parsing

  • Parsing RSS feed to android application 2011-02-10

    I'm building a hunting application for which I need weather information in form of a RSS feed from this site. I've used the code from this site and it list the feeds, but when I click on an item it doesn't connect it to the site for more information.

  • Parsing RSS Feed with JSON and Populating a List Android App 2010-10-27

    Im brand new to Android Application development and I am working on an application that will get an RSS feed from a specific url that returns JSON data , what I am wondering is what is the best way to translate this from JSON to populate the list , I

  • Android Pull Parsing RSS feeds troubles 2010-12-12

    I am working on a very simple RSS reader for Android as a learning experience. I decided to use the XmlPullParser for parsing the feeds as it is quite simple and has an acceptable level of efficiency (for my needs). I am getting an error while trying

  • Parsing an RSS Feed in an Android Application 2012-04-21

    I am trying to retrieve data from an RSS Feed. My program is working well, with one exception. The feed has items that are structured as: <title></title> <link></link> <description></description> I can retrieve the

  • Adapter fetches and parses RSS feed to get its data - best practice? 2010-12-05

    In a shared project, we have an Adapter class (extends BaseAdapter, implements ListAdapter). In its constructor, this class fetches an RSS feed from the internet and parses the returned XML document to obtain the data it will 'adapt'; the data is kep

  • creating a list by parsing rss feeds using java 2011-07-15

    Hiiii, i want to create a list of articles by parsing the rss feeds from a website.Can anyone suggest me how to create such a list. --------------Solutions------------- You could take a look at the Rome library ( It'll

  • Problem parsing Rss feed using javascript 2011-08-03

    I am trying to read two Rss feed urls at regular intervals and display the latest feed title as a notification inside my android app. As the setinterval function is being called every 8000 ms I want to make sure there are no duplicate notifications o

  • Parsing RSS feeds with PHP 2009-08-10

    I am successfully parsing an RSS feed with PHP, but want to return a message when the feed is empty. I have included the PHP File here to show you what I want to achieve. I'm looking for it to break or stop executing, but print a message and stop at

  • How to parse RSS Feed and display it as Links in Blackberry Application? 2010-03-13

    I wanted to parse the xml feed and display as links in my Blackberry application. After googling it, i found out that i have to use SAX parser. I have not found any good example. For example if i want to parse the news rss feed from How to

  • When parsing RSS feed, wrong date is displayed 2010-07-04

    Here is my code: <?php $RSSFEEDS = array( 0 => "", ); function FormatRow($date, $title, $link, $description) { return <<<HTML <p class="blogdate">$date</p><h2 class="blogtitle">$tit

  • What module can I use to parse RSS feeds in a Perl CGI script? 2010-07-06

    I am trying to find a RSS parser that can be used with a Perl CGI script. I found simplepie and that's really easy parser to use in PHP scripting. Unfortunately that doesn't work with a Perl CGI script. Please let me know if there is anything that's

  • parse rss feed while exclude some text 2011-03-26

    i am trying to parse the user names from an rss feed using php, but for some reason its not working correctly here is my code. $feedDom = new DomDocument(); $feedDom ->load($TURL); $xPath = new DomXPath($TwitterDom); $usernames = $xPath->xpath(

  • How to combine and parse RSS feeds? 2011-07-02

    What would be the easiest way to go about combining multiple (3+) RSS feeds in PHP? Kind of like how Yahoo Pipes allows you to do it, but I want the code to be entirely on my site instead of being embedded from elsewhere. The long-term goal would be

  • how to get rss feed in an android app page from a live website? 2011-07-17

    I have an ASP.NET website and I want to develop simple android application with 1 page in which I want to get live data from RSS FEED of my website. The link of my website rss feed is like: In t

  • parse RSS feed with PERL using XML:LibXML 2011-09-15

    I am in the unfortunate position of needing to parse a RSS feed since there is no other way to obtain the data. I have a Perl script that has worked before to parse an XML file. I figured I could modify it to do the same for the RSS feed so I can get

  • Parse RSS feed to XML using Jquery? 2011-09-16

    Can anyone recommend the best way to parse an RSS feed into variables so that I can use in a styled page? I would like to parse an RSS news feed in a way that I can use the first two stories to show images/story links - then further links to show sto

  • While parsing RSS feed through Rome getting Content is not allowed in prolog 2011-12-12

    Using Rome API to parse the RSS feeds I am getting this error : Invalid XML at The code is as below: public static void main(String[] args

  • how to open RSS feed url in android? 2011-12-14

    i want to open RSS feed URL like yahoo in android WebView. i used webView.loadUrl(urlString) method.if i use this,a page having full of html data with >html,img...tags opens.its not opening the original webpage. how to open that URL in webView

  • Odd character being returned when parsing RSS feed descriptions 2011-12-17

    When parsing the <description> tags found in several RSS feeds, I'm noticing that if they end with [...], the value being displayed in my list is just the close bracket character ]. Here is but one example: <description> <![CDATA[ Warm

  • Which is the best method to parse RSS Feeds in iphone 2011-12-21

    I want to make an iphone application for a blog. Which is the best method to parse the RSS feeds from the blog. --------------Solutions------------- Just use this MWFeedParser In the RootViewController files

  • Cannot parse RSS feed 2012-02-22

    I'm trying to parse the RSS feed from but can't search by element name for some reason. I'm following the instructions from this page but his example doesn't seem to work on the fanfiction site ab

  • Parse RSS feed using c# 2011-08-02

    I have an RSS feed that I follow and would like to display it on my website. The UI would simply contain the description of the article in the RSS feed and also have the link to click on. Since I'm using the ASP.NET C# framework, I'm wondering if thi

Copyright (C), All Rights Reserved.

processed in 0.125 (s). 12 q(s)