Please help me with this code - I am basically going through a book and trying to create the examples myself but I can't get past this error. I've checked my LogCat and it says "java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'". I know there is probably some small detail I'm omitting that is causing this but I can't put my finger on it - it is almost an exact copy of a working program example given by the book. I am trying to create a simple ArrayAdapter and feed it a dummy list. Here are the three files of interest:
package com.example.bwett.SimpleList;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class SimpleList extends ListActivity {
String[] item = {"Item1", "Item2", "Item3", "Item4",
"Item5", "Item6", "Item7", "Item8"};
TextView mainLabel;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
setListAdapter(new ArrayAdapter<String> (this,
R.layout.row,
R.id.label,
item));
mainLabel = (TextView)findViewById(R.id.mainLabel);
}
public void onListItemClick(ListView parent, View v,
int position, long id){
mainLabel.setText(item[position]);
}
}
MAIN.XML:
<?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">
<TextView
android:id="@+id/mainLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
</LinearLayout>
ROW.XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ok"
android:layout_width="22px"
android:layout_height="fill_parent"
android:padding="2px"
android:src="@drawable/icon"/>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textSize="44sp"/>
</LinearLayout>