3

In my project whenever I extend activity it works fine but as soon as I extend ListActivity it throws exception and shows file not found. Why is that? We already know that ListActivity itself extends the Activity class. The application must run 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 the exception. I need to bring this change because I want to implement it on ListView instead of TextView.

Error it throws: debug mode gets active and it highlights under Suspended(exception RunTimeException): ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2663.

6
  • Maybe post your code / layout file to see what your doing? I extend list activity all the time without exception Commented Jul 2, 2010 at 11:17
  • ...and add what exception (FileNotFoundException)? Do you see which file? Do you have a logcat extract? Commented Jul 2, 2010 at 11:24
  • I have added my code.. trying to grab feeds of a particular site and display it. Commented Jul 2, 2010 at 11:24
  • debug mode gets active and it shows under Suspended(exception RunTimeException): ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2663 as highlighted. Commented Jul 2, 2010 at 11:27
  • 1
    which file is not found after the change? You may need to change some configuration files or regenerate the R class after the change. Commented Jul 2, 2010 at 11:28

2 Answers 2

2

When you extend a ListActivity, it is expecting the Layout to have a ListView that has an id of "@android:id/list", if you do not have it, it will throw an exception

You layout should look something like this:

<?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>
Sign up to request clarification or add additional context in comments.

Comments

0

Without seeing your main.xml or the exception I can't be sure, but I'd suggest checking if your list has the @android:id/list identity as required.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.