[RESOLVED] RSS code on android 4+« Back to Previous Page

I have problem in Android "AsyncTask RSS Reader" post. I take your code but is not working with me. It gives me run time error, befor this I am using - "How to write Android RSS parser" post, but also does not work, because I am working on Android4+. I edit the code according "AsyncTask RSS Reader" post but also does not work. Please help me. Thank you for your cooperation.
Posted by Nora (Questions:4, Answers:5)
Asked on July 17, 2013 12:13 pm
Category: Android
0

Thank you my problem is resolved

Posted by Nora (Questions:4, Answers:5)
Answered On July 18, 2013 3:20 pm #
1

This is because your RssItem class is missing toString method. Try this implementation and it will work.


public String toString() {
return title;
}
Posted by itcuties (Questions:2, Answers:18)
Answered On July 18, 2013 12:23 pm #
0

Sorry,I want to upload the picture but I can’t
but is shows to me data like that
com.example.newsrss.data.RssItem@41c84a58??

Posted by Nora (Questions:4, Answers:5)
Answered On July 18, 2013 10:10 am #
0

Thanks for you very much
but,I want to ask you last questions why the data in a list is shown like that (in picture),is not shows the data form RSS

Posted by Nora (Questions:4, Answers:5)
Answered On July 18, 2013 10:03 am #
1

Hello Nora, thanks for uploading your code. The problem was in your implementation of the RssParseHandler class. There was a typo – RSS feed doesn’t contain ”items” tag but ”item” tag where each RSS item’s data is stored. Here is our implementation of the RssParseHandler class:


package com.example.newsrss.util;
import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.example.newsrss.data.RssItem;

/**
* SAX tag handler
*
* @author ITCuties
*
*/
public class RssParseHandler extends DefaultHandler {

private List<RssItem> rssItems;

// Used to reference item while parsing
private RssItem currentItem;

// Parsing title indicator
private boolean parsingTitle;
// A buffer used to build current title being parsed
private StringBuffer currentTitleSb;

private StringBuffer currentLinkSb;

// Parsing link indicator
private boolean parsingLink;

public RssParseHandler() {
rssItems = new ArrayList<RssItem>();
}

public List<RssItem> getItems() {
return rssItems;
}

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {

if ("item".equals(qName)) {
currentItem = new RssItem();
} else if ("title".equals(qName)) {
parsingTitle = true;

currentTitleSb = new StringBuffer();
} else if ("link".equals(qName)) {
parsingLink = true;

currentLinkSb = new StringBuffer();
}
}

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {

if ("item".equals(qName)) {
rssItems.add(currentItem);
currentItem = null;
} else if ("title".equals(qName)) {

parsingTitle = false;

// Set item's title when we parse item->title tag not the channel title tag
if (currentItem != null) {
// Set item's title here
currentItem.setTitle(currentTitleSb.toString());
}

} else if ("link".equals(qName)) {
parsingLink = false;

if (currentItem != null) {
// Set item's title here
currentItem.setLink(currentLinkSb.toString());
}

}
}

@Override
public void characters(char[] ch, int start, int length) throws SAXException {

if (parsingTitle) {
if (currentItem != null) {
// Here we append the title to the buffer due to network issues.
// Sometimes this characters method is called multiple times for a tag contents.
currentTitleSb.append(new String(ch, start, length));
}
} else if (parsingLink) {
if (currentItem != null) {
currentLinkSb.append(new String(ch, start, length));
}
}
}

}

Posted by itcuties (Questions:2, Answers:18)
Answered On July 17, 2013 9:37 pm #
No account?



It's FREE!

Like what you have found?


... and keep us going