我的第一个应用程序活动出错.错误是:“应用程序意外停止”
我的第一个xml活动是visit_record.xml
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
我为这个活动创建的课程是:
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;
}}
});
}}
请指导我为什么它会给出错误并且不能在手机中运行应用程序.
最佳答案 你已经扩展了ListActivity,当你这样做时,你的ListView必须有id android:id =“@ android:id / list”.你错过了.
<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" >
查看此question以获取更多详细信息.