4

error occur on my first activity of application. Error is: "application stopped unexpectedly"

My first xml activity is visit_record.xml

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >    

I've created class for this activity is: visit_record.java

public class visit_record extends ListActivity {
    static final String[] LIST = new String[] {"My Task", "Task Execution", "Non-Ticket Task"};

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



    setListAdapter(new ArrayAdapter<String>(this, R.layout.visit_record,LIST));

    ListView listView = getListView();
    listView.setTextFilterEnabled(true);

    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // When clicked, show a toast with the TextView text

            Intent intent;
            switch (position) {
               case 0:
               intent= new Intent(visit_record.this, My_Task.class);
                startActivity(intent);
              break;
                case 1:
                    intent=new Intent(visit_record.this, task_execution.class);
                    startActivity(intent);
                    break;
                case 2:
                    intent=new Intent(visit_record.this, non_ticket_task.class);
                    startActivity(intent);  
                    break;

                   default:
                    break;
            }}

    });
}}

Kindly guide me why it gives error and not run application in mobile phone.

Mona
  • 267
  • 1
  • 4
  • 9

1 Answers1

2

You have extended ListActivity and when you do that your ListView must have the id android:id="@android:id/list". You missed it.

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >    

Check this question for more details.

Community
  • 1
  • 1
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
  • on error Log: keybinding conflict occur:( it still not resolve Andro. by add adding id:( – Mona Nov 29 '12 at 11:54
  • better post your logcat by editing your question. I can't get you. – Andro Selva Nov 29 '12 at 11:55
  • it gives error "unable to start service intent if Etrack activity" EtrackActivity is my another project. in this project no error occur except brightness or light errors – Mona Nov 29 '12 at 12:12