Android特定的RSS Feed阅读器问题

时间:2012-10-15 23:41:05

标签: android rss rss-reader

我正在尝试使用此Feed地址运行我在线找到的教程:http://feeds.feedburner.com/TheTechnologyEdge

我可以在使用其他RSS源时正常运行程序,但我特别需要上面列出的Feed。我确信解决方案相对简单,但我似乎无法弄清楚为什么这个地址不起作用而其他人会这样做。以下是我正在使用的代码。

public class SolsticeRSSReaderActivity extends ListActivity

{

@SuppressWarnings("rawtypes")
private List headlines;

@SuppressWarnings("rawtypes")
private List links;

/** Called when the activity is first created. */
@SuppressWarnings(
{ "unchecked", "rawtypes" })
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    headlines = new ArrayList();
    links = new ArrayList();

    try
    {
        URL url = new URL("http://feeds2.feedburner.com/TheTechnologyEdge");

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

        // We will get the XML from an input stream
        xpp.setInput(getInputStream(url), "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"))
            {
                insideItem = false;
            }

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

    }
    catch (MalformedURLException e)
    {
        e.printStackTrace();
    }
    catch (XmlPullParserException e)
    {
        e.printStackTrace();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }

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

    setListAdapter(adapter);

}

/*
 * take as an argument the feed url, and returns the input stream
 */
public InputStream getInputStream(URL url)
{
    try
    {
        return url.openConnection().getInputStream();
    }
    catch (IOException e)
    {
        return null;
    }
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
    Uri uri = Uri.parse(links.get(position) + "");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);
}

}

我修复了Atom问题后,当我尝试实现我的监听器时,我收到了这个错误。我在调试中跟踪了一下,看起来我的uri变量是null,并且不像我在使用它作为RSS提要时那样包含html。

10-15 20:10:32.445: E/AndroidRuntime(17621): FATAL EXCEPTION: main
10-15 20:10:32.445: E/AndroidRuntime(17621): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat= }
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1536)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1388)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.app.Activity.startActivityForResult(Activity.java:3195)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.app.Activity.startActivity(Activity.java:3302)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at bmjohns.solstice.SolsticeRSSReaderActivity.onListItemClick(SolsticeRSSReaderActivity.java:142)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.widget.AdapterView.performItemClick(AdapterView.java:292)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.widget.AbsListView.performItemClick(AbsListView.java:1366)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2995)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.widget.AbsListView$1.run(AbsListView.java:3790)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.os.Handler.handleCallback(Handler.java:605)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.os.Looper.loop(Looper.java:137)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at android.app.ActivityThread.main(ActivityThread.java:4514)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at java.lang.reflect.Method.invokeNative(Native Method)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at java.lang.reflect.Method.invoke(Method.java:511)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
10-15 20:10:32.445: E/AndroidRuntime(17621):    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

此URL使用Atom,而不是RSS。文章开头/结尾

entry

item