Problem with ListActivity Extension

In my project, whenever I expand the activity, it works fine, but as soon as I expand the ListActivity, it throws an exception and shows that the file was not found. Why is this? We already know that ListActivity extends the Activity class itself. The application should work fine.

Here's the java file:

package com.android.feedGrabber;

import java.net.URL;
import java.net.URLConnection;
import java.util.Collection;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import com.sun.cnpi.rss.elements.Item;
import com.sun.cnpi.rss.elements.Rss;
import com.sun.cnpi.rss.parser.RssParser;
import com.sun.cnpi.rss.parser.RssParserFactory;

public class feedGrabber extends Activity {
    public static Collection<Item> readRSSDocument(String url) throws Exception {
                RssParser parser = RssParserFactory.createDefault();
                URL feedUrl = new URL(url);
                URLConnection urlc=feedUrl.openConnection();
                urlc.setRequestProperty("User-Agent","");
                urlc.connect();
                Rss rss = parser.parse(urlc.getInputStream());
                return rss.getChannel().getItems();
        }
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        int links=0;
        try
        {
        for(Item item : feedGrabber.readRSSDocument("http://feeds.feedburner.com/Tutorialzine")){
                if(links++>3)
                        break;
                TextView t = (TextView)findViewById(R.id.title);
                t.append("Title: ");
                t.append(item.getTitle().toString());
                t.append("\n\n");

                //System.out.println("Title: " + item.getTitle());
                //System.out.println("Link: " + item.getLink());
        }
        }catch(Exception e)
        {
            //
        }
      }
}

If I change "extends Activity" to "extends ListActivity", it gives an exception. I need to make this change because I want to implement it in a ListView instead of a TextView.

Error: debug mode is activated, and it is highlighted in the Suspended section (RunTimeException exception): ActivityThread.performLaunchActivity (ActivityThread $ ActivityRecord, Intent): 2663.

+3
2

ListActivity , ListView "@android: id/list", ,

:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    <TextView android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/noresults"/>
</LinearLayout>
+2

main.xml , , , @android:id/list .

0

Source: https://habr.com/ru/post/1752804/


All Articles