简体   繁体   中英

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

<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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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