android rss提要阅读器问题

时间:2011-07-20 15:35:22

标签: android android-layout android-widget

我想为Android开发RSS FEED阅读器。我正在学习本教程 http://www.ibm.com/developerworks/xml/tutorials/x-androidrss/downloads.html

我没有在程序中收到任何错误但没有获得所需的输出

这是我的logcat:

07-20 16:12:23.531: ERROR/Zygote(33): setreuid() failed. errno: 2
07-20 16:12:35.101: ERROR/Zygote(33): setreuid() failed. errno: 17
07-20 16:12:37.031: ERROR/BatteryService(59): usbOnlinePath not found
07-20 16:12:37.031: ERROR/BatteryService(59): batteryVoltagePath not found
07-20 16:12:37.031: ERROR/BatteryService(59): batteryTemperaturePath not found
07-20 16:12:37.061: ERROR/SurfaceFlinger(59): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
07-20 16:12:47.381: ERROR/EventHub(59): could not get driver version for /dev/input/mouse0, Not a typewriter
07-20 16:12:47.412: ERROR/EventHub(59): could not get driver version for /dev/input/mice, Not a typewriter
07-20 16:12:47.812: ERROR/System(59): Failure starting core service
07-20 16:12:47.812: ERROR/System(59): java.lang.SecurityException
07-20 16:12:47.812: ERROR/System(59):     at android.os.BinderProxy.transact(Native Method)
07-20 16:12:47.812: ERROR/System(59):     at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
07-20 16:12:47.812: ERROR/System(59):     at android.os.ServiceManager.addService(ServiceManager.java:72)
07-20 16:12:47.812: ERROR/System(59):     at com.android.server.ServerThread.run(SystemServer.java:184)
07-20 16:12:49.591: ERROR/SoundPool(59): error loading /system/media/audio/ui/Effect_Tick.ogg
07-20 16:12:49.591: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressStandard.ogg
07-20 16:12:49.602: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressSpacebar.ogg
07-20 16:12:49.612: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressDelete.ogg
07-20 16:12:49.622: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressReturn.ogg
07-20 16:12:52.672: ERROR/ThrottleService(59): Could not open GPS configuration file /etc/gps.conf
07-20 16:12:54.551: ERROR/logwrapper(145): executing /system/bin/tc failed: No such file or directory
07-20 16:12:54.691: ERROR/logwrapper(147): executing /system/bin/tc failed: No such file or directory
07-20 16:12:54.781: ERROR/logwrapper(149): executing /system/bin/tc failed: No such file or directory
07-20 16:13:17.789: ERROR/HierarchicalStateMachine(59): TetherMaster - unhandledMessage: msg.what=3
07-20 16:13:38.669: INFO/ActivityManager(59): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=268 uid=10028 gids={}
07-20 16:13:38.689: WARN/RecognitionManagerService(59): no available voice recognition services found
07-20 16:13:39.370: DEBUG/dalvikvm(59): GC_EXPLICIT freed 9347 objects / 593752 bytes in 302ms
07-20 16:13:39.590: DEBUG/dalvikvm(165): GC_EXPLICIT freed 2883 objects / 156272 bytes in 1275ms
07-20 16:13:39.659: INFO/installd(35): unlink /data/dalvik-cache/data@app@com.msi.androidrss-1.apk@classes.dex
07-20 16:13:39.782: DEBUG/AndroidRuntime(118): Shutting down VM
07-20 16:13:39.789: DEBUG/jdwp(118): adbd disconnected
07-20 16:13:39.809: INFO/AndroidRuntime(118): NOTE: attach of thread 'Binder Thread #3' failed
07-20 16:13:39.879: INFO/ActivityThread(268): Publishing provider com.svox.pico.providers.SettingsProvider: com.svox.pico.providers.SettingsProvider
07-20 16:13:40.131: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
07-20 16:13:40.429: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
07-20 16:13:40.511: DEBUG/AndroidRuntime(278): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
07-20 16:13:40.511: DEBUG/AndroidRuntime(278): CheckJNI is ON
07-20 16:13:41.740: INFO/ActivityManager(59): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 50234 ms (total 50234 ms)
07-20 16:13:42.340: DEBUG/AndroidRuntime(278): --- registering native functions ---
07-20 16:13:43.790: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.msi.androidrss/.ShowDescription }
07-20 16:13:43.890: DEBUG/AndroidRuntime(278): Shutting down VM
07-20 16:13:43.910: DEBUG/jdwp(278): adbd disconnected
07-20 16:13:43.960: INFO/AndroidRuntime(278): NOTE: attach of thread 'Binder Thread #3' failed
07-20 16:13:44.099: INFO/ActivityManager(59): Start proc com.msi.androidrss for activity com.msi.androidrss/.ShowDescription: pid=286 uid=10042 gids={1015}
07-20 16:13:45.939: INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x2ff7e0:0x2ff8ec] in 7962326 ns
07-20 16:13:46.670: INFO/ActivityManager(59): Displayed activity com.msi.androidrss/.ShowDescription: 2691 ms (total 2691 ms)

这是我的manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.msi.androidrss"
      android:versionCode="1"
      android:versionName="1.0">


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".ShowDescription"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

            </intent-filter>
        </activity>

    </application>
</manifest>

这是我的.java程序之一“RSSReader.java”

package com.msi.androidrss;

import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.widget.TextView;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener; 
import android.util.Log;
import java.net.URL;

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

import org.xml.sax.InputSource;

import org.xml.sax.XMLReader;

import android.content.Intent;

import com.msi.androidrss.ShowDescription;

public class RSSReader extends Activity implements OnItemClickListener
{

    public final String RSSFEEDOFCHOICE = "http://www.ibm.com/developerworks/views/rss/customrssatom.jsp?zone_by=XML&zone_by=Java&zone_by=Rational&zone_by=Linux&zone_by=Open+source&zone_by=WebSphere&type_by=Tutorials&search_by=&day=1&month=06&year=2007&max_entries=20&feed_by=rss&isGUI=true&Submit.x=48&Submit.y=14";

    private static final int SELECT = 0;
    private static final int REFRESH = 1;

    public final String tag = "RSSReader";
    private RSSFeed feed = null;

    /** Called when the activity is first created. */

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        // go get our feed!
        feed = getFeed(RSSFEEDOFCHOICE);

        // display UI
        UpdateDisplay();

    }


    private RSSFeed getFeed(String urlToRssFeed)
    {
        try
        {
            // setup the url
           URL url = new URL(urlToRssFeed);

           // create the factory
           SAXParserFactory factory = SAXParserFactory.newInstance();
           // create a parser
           SAXParser parser = factory.newSAXParser();

           // create the reader (scanner)
           XMLReader xmlreader = parser.getXMLReader();
           // instantiate our handler
           RSSHandler theRssHandler = new RSSHandler();
           // assign our handler
           xmlreader.setContentHandler(theRssHandler);
           // get our data via the url class
           InputSource is = new InputSource(url.openStream());
           // perform the synchronous parse           
           xmlreader.parse(is);
           // get the results - should be a fully populated RSSFeed instance, or null on error
           return theRssHandler.getFeed();
        }
        catch (Exception ee)
        {
            // if we have a problem, simply return null
            return null;
        }
    }
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        super.onCreateOptionsMenu(menu);
     menu.add(0, RSSReader.SELECT, 0, "Choose RSS Feed").setIcon(android.R.drawable.ic_menu_mapmode);
        //menu.add(0,0,"Choose RSS Feed");
        //menu.add(0,1,"Refresh");
     menu.add(0, RSSReader.REFRESH, 0, "Refresh").setIcon(android.R.drawable.ic_menu_mapmode);
        Log.i(tag,"onCreateOptionsMenu");
        return true;
    }

    @Override
    public boolean onMenuItemSelected(final int featureId, final MenuItem item) {
        switch (item.getItemId()) {
        case RSSReader.SELECT:

            Log.i(tag,"Set RSS Feed");
            return true;
        case RSSReader.REFRESH:
            Log.i(tag,"Refreshing RSS Feed");
            return true;
        }
        return false;
    }


    private void UpdateDisplay()
    {
        TextView feedtitle = (TextView) findViewById(R.id.feedtitle);
        TextView feedpubdate = (TextView) findViewById(R.id.feedpubdate);
        ListView itemlist = (ListView) findViewById(R.id.itemlist);


        if (feed == null)
        {
            feedtitle.setText("No RSS Feed Available");
            return;
        }

        feedtitle.setText(feed.getTitle());
        feedpubdate.setText(feed.getPubDate());

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

        itemlist.setAdapter(adapter);

        itemlist.setOnItemClickListener(this);

        itemlist.setSelection(0);

    }




    public void onItemClick(AdapterView<?> parent, View v, int position, long id)

     {
         Log.i(tag,"item clicked! [" + feed.getItem(position).getTitle() + "]");

         Intent itemintent = new Intent(this,ShowDescription.class);

         Bundle b = new Bundle();
         b.putString("title", feed.getItem(position).getTitle());
         b.putString("description", feed.getItem(position).getDescription());
         b.putString("link", feed.getItem(position).getLink());
         b.putString("pubdate", feed.getItem(position).getPubDate());

         itemintent.putExtra("android.intent.extra.INTENT", b);

         startActivity(itemintent);
     }

}

这是我的.java程序之一“ShowDescription.java”

package com.msi.androidrss;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.content.Intent;
import android.view.*;

public class ShowDescription extends Activity 
{
    public void onCreate(Bundle icicle) 
    {
        super.onCreate(icicle);
        setContentView(R.layout.showdescription);

        String theStory = null;


        Intent startingIntent = getIntent();

        if (startingIntent != null)
        {
            Bundle b = startingIntent.getBundleExtra("android.intent.extra.INTENT");
            if (b == null)
            {
                theStory = "bad bundle?";
            }
            else
            {
                theStory = b.getString("title") + "\n\n" + b.getString("pubdate") + "\n\n" + b.getString("description").replace('\n',' ') + "\n\nMore information:\n" + b.getString("link");
            }
        }
        else
        {
            theStory = "Information Not Found.";

        }

        TextView db= (TextView) findViewById(R.id.storybox);
        db.setText(theStory);

        Button backbutton = (Button) findViewById(R.id.back);

        backbutton.setOnClickListener(new Button.OnClickListener() 
        {
            public void onClick(View v) 
            {
                finish();
            }
        });        
    }
}

作为输出我得到“坏包”,为什么?

帮助!!!

2 个答案:

答案 0 :(得分:0)

从您的logcat输出判断,您正在从Launcher启动ShowDescription活动。如果是这种情况 - 难怪它在开始意图中没有任何额外的。

因为就代码而言,只有当从RSSReader Activity启动此活动时才将BundleExtra放入起始意图。

答案 1 :(得分:0)

确保将.RSSReader添加到清单文件中,并将此行添加到清单文件中:

 <uses-permission android:name="android.permission.INTERNET" />
相关问题