-1

I've got an activity which is formed by four buttons. When I click one of them I go to another activity. All the buttons work well, but when I click the fourth the app stops. The activity must be started is formed by a ListView. Here is the code of that activity:

public class InformationActivity extends ListActivity {

String[] elements = {"About", "Rate"};

public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);

     setContentView(R.layout.information_layout); 
     ListView listview = (ListView)findViewById(R.id.optionslist);
     listview.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, elements));
 }

public void onListItemClick(ListView parent, View v, int position, long id) {

    if ("About".equals(elements[position]))
        {Intent i = new Intent(this, AboutActivity.class);
        startActivity(i);}
    else if ("Rate".equals(elements[position]))
        {Intent i = new Intent(this, FeedbackActivity.class);
        startActivity(i);}
    }

}

Checking the LogCat, I find the following error:

08-22 12:34:57.649: E/AndroidRuntime(1361): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.isa.gestordecurso/com.isa.gestordecurso.InformationActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

I don't understand the error. The id of the ListView in the XML is optionslist, which is defined in the Activity.

Hope there's a solution: Thanks!

Isaías
  • 491
  • 2
  • 9
  • 20

1 Answers1

1

The fourth activity is a ListActivity, the list activity take default id for list view as @android:id/list, that is why it is saying

Your content must have a ListView whose id attribute is 'android.R.id.list'

You should use following id for list view =>@android:id/list

<ListView android:id="@android:id/list"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:background="#00FF00"
               android:layout_weight="1"
               android:drawSelectorOnTop="false"/>`

For more on ListActivity, Read Developer Android here

Akhil Jain
  • 13,872
  • 15
  • 57
  • 93