1st activity not working

The error occurs during my first application action. Error: "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 created a class for this operation: 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; }} }); }} 

Tell me why this gives an error and does not launch the application on a mobile phone.

+4
source share
1 answer

You have an extended ListActivity function, and when you do this, the ListView should 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" > 

More on this.

+2
source

All Articles