简体   繁体   English

没有运行第一个活动

[英]not running 1st activity

error occur on my first activity of application. 我的第一个应用程序活动发生错误。 Error is: "application stopped unexpectedly" 错误是:“应用程序意外停止”

My first xml activity is visit_record.xml 我的第一个xml活动是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 我为此活动创建了一个类: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. 请指导我为什么会出错并且无法在手机中运行应用程序。

You have extended ListActivity and when you do that your ListView must have the id android:id="@android:id/list" . 您已经扩展了ListActivity,并且当您这样做时,ListView必须具有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. 检查此问题以获取更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM