Only error showing is null, rss feed reader not working

Posted by Callum on Stack Overflow See other posts from Stack Overflow or by Callum
Published on 2014-08-25T10:15:44Z Indexed on 2014/08/25 10:20 UTC
Read the original article Hit count: 255

Filed under:
|

I have been following a tutorial which is showing me how to create an rssfeed reader, I come to the end of the tutorial; and the feed is not displaying in the listView. So I am looking for errors in logCat, but the only one I can find is one just saying 'null', which is not helpful at all.

Can anyone spot a potential problem with the code I have written?

Thanks.

DirectRSS(main class):

   package com.example.rssapplication;

import java.util.List;

import android.app.ListActivity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class DirectRSS extends ListActivity{



     @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.directrss);
            //Set to portrait, so that every time the view changes; it does not run the DB query again...
            setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
           try{
               RssReader1 rssReader = new RssReader1("http://www.skysports.com/rss/0,20514,11661,00.xml");

               ListView list = (ListView)findViewById(R.id.list);

               ArrayAdapter<RssItem1> adapter = new ArrayAdapter<RssItem1>(this, android.R.layout.simple_list_item_1);

               list.setAdapter(adapter);

               list.setOnItemClickListener(new ListListener1(rssReader.getItems(),this));
           }catch(Exception e)
           {
               String err = (e.getMessage()==null)?"SD Card failed": e.getMessage();
               Log.e("sdcard-err2:",err + " " + e.getMessage()); 
              // Log.e("Error", e.getMessage());

               Log.e("LOGCAT", "" + e.getMessage());
           }

        }



     }

ListListener1:

package com.example.rssapplication;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public class ListListener1 implements OnItemClickListener{

    List<RssItem1> listItems;
    Activity activity;

    public ListListener1(List<RssItem1> listItems, Activity activity)
    {
        this.listItems = listItems;
        this.activity = activity;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
        // TODO Auto-generated method stub
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(listItems.get(pos).getLink()));

        activity.startActivity(i);

    }

}

RssItem1:

package com.example.rssapplication;

public class RssItem1 {

    private String title;
    private String link;


    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getLink() {
        return link;
    }
    public void setLink(String link) {
        this.link = link;
    }



}

RssParseHandler1:

package com.example.rssapplication;

import java.util.ArrayList;
import java.util.List;

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

public class RssParseHandler1 extends DefaultHandler{

    private List<RssItem1> rssItems;
    private RssItem1 currentItem;
    private boolean parsingTitle;
    private boolean parsingLink;

    public RssParseHandler1(){
        rssItems = new ArrayList<RssItem1>();

    }

    public List<RssItem1> getItems(){

        return rssItems;
    }

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

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

        // TODO Auto-generated method stub
        super.startElement(uri, localName, qName, attributes);
    }


    @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;
        }
        else if("link".equals(qName)){
            parsingLink = false;
        }


        // TODO Auto-generated method stub
        super.endElement(uri, localName, qName);
    }

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

        if(parsingTitle)
        {
            if(currentItem!=null)
            {
                currentItem.setTitle(new String(ch,start,length));
            }

        }
        else if(parsingLink)
        {
            if(currentItem!=null)
            {
                currentItem.setLink(new String(ch,start,length));
                parsingLink = false;
            }

        }
        // TODO Auto-generated method stub
        super.characters(ch, start, length);
    }

}

RssReader1:

package com.example.rssapplication;

import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

public class RssReader1 {

    private String rssUrl;

    public RssReader1(String rssUrl)
    {
        this.rssUrl = rssUrl;
    }

    public List<RssItem1> getItems() throws Exception
    {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();

        RssParseHandler1 handler = new RssParseHandler1();

        saxParser.parse(rssUrl, handler);

        return handler.getItems();
    }

}

Here is the logCat also:

  08-25 11:13:20.803: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:20.803: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:20.803: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:20.813: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:20.813: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:20.813: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:20.813: W/ApplicationPackageManager(26291): getCSCPackageItemText()
08-25 11:13:20.843: D/AbsListView(26291): Get MotionRecognitionManager
08-25 11:13:20.843: E/sdcard-err2:(26291): SD Card failed null
08-25 11:13:20.843: E/LOGCAT(26291): null
08-25 11:13:20.843: D/AbsListView(26291): onVisibilityChanged() is called, visibility : 4
08-25 11:13:20.843: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:20.873: D/AbsListView(26291): onVisibilityChanged() is called, visibility : 0
08-25 11:13:20.883: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:20.903: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:20.933: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:20.963: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:20.973: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:21.323: D/AbsListView(26291): onVisibilityChanged() is called, visibility : 4
08-25 11:13:21.323: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:21.323: D/AbsListView(26291): onVisibilityChanged() is called, visibility : 4
08-25 11:13:21.323: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:21.323: D/AbsListView(26291): onVisibilityChanged() is called, visibility : 4
08-25 11:13:21.323: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:21.323: D/AbsListView(26291): onVisibilityChanged() is called, visibility : 4
08-25 11:13:21.323: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:21.323: D/AbsListView(26291): onVisibilityChanged() is called, visibility : 4
08-25 11:13:21.323: D/AbsListView(26291): unregisterIRListener() is called 
08-25 11:13:21.333: D/AbsListView(26291): onVisibilityChanged() is called, visibility : 4
08-25 11:13:21.333: D/AbsListView(26291): unregisterIRListener() is called 

© Stack Overflow or respective owner

Related posts about android

Related posts about rss