tags:

views:

412

answers:

1

hi,

I am getting a run time exception java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

I dont know what is wrong>can anyone please help me

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newslist);
    mDbHelper.open();
    fillData();

}

private void fillData() {

    Bundle extras = getIntent().getExtras();
    long catID = extras.getLong("cat_id");

    Cursor c = mDbHelper.fetchNews(catID);
    startManagingCursor(c);

    String[] from = new String[] { DBHelper.KEY_TITLE };
    int[] to = new int[] { R.id.newslist_text };

    SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
            R.layout.text_newslist, c, from, to);
    setListAdapter(notes);

}

newslist.xml

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ListView android:id="@+id/catnewslist" android:layout_width="wrap_content"
    android:layout_height="wrap_content"></ListView>
   </LinearLayout>

text_newslist.xml

  <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
  <TextView android:text="@+id/newslist_text" android:id="@+id/newslist_text"
    android:layout_width="wrap_content"    android:layout_height="wrap_content">    
</TextView>
</LinearLayout>
A: 

Remove the call to setContentView - you don't need it in a ListActivity unless you're doing something radical. The code should work without it.

Ben L.
Thank you for your reply.removed it.I am getting a syntax error here@Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); db.execSQL("INSERT INTO new VALUES(1,0,'aa','aaa','aa';") ; db.execSQL("INSERT INTO new VALUES(2,0,'bb','bbb','bb;");}Can you help me with this.
raji
you are missing a bracket in each of your db.execSQL statements:@Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); db.execSQL("INSERT INTO new VALUES(1,0,'aa','aaa','aa');"); db.execSQL("INSERT INTO new VALUES(2,0,'bb','bbb','bb');");}... but really that should be a NEW question.
Aurora