0

我是一名 android 初学者,我尝试创建一个员工目录。但是每次运行项目时,我都会收到此错误: 在此处输入图像描述

在此处输入图像描述

这是 mai main.xml 文件代码:

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

<LinearLayout
    android:orientation="horizontal"
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/searchText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:inputType="text" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/searchButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/search" />
</LinearLayout>

<ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

这是 mai java 类:

public class EmployeeList extends ListActivity  {
protected EditText searchText;
protected SQLiteDatabase db;
protected Cursor cursor;
protected ListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    db = (new DatabaseHelper(this)).getWritableDatabase();
    searchText = (EditText)findViewById(R.id.searchText);
}

@SuppressWarnings("deprecation")
public void search(View view){
    cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employee WHERE firstName || ' ' || lastName LIKE ?", 
                        new String[]{"%" + searchText.getText().toString() + "%"});
    adapter = new SimpleCursorAdapter(this, R.layout.employee_list_item, 
                                    cursor, new String[]{"firstName", "lastName", "title"}, 
                                    new int[] {R.id.firstName, R.id.lastName, R.id.title});
    setListAdapter(adapter);
}
public void onListItemClick(ListView parent, View view, int position, long id) {
    Intent intent = new Intent(this, EmployeeDetails.class);
    Cursor cursor = (Cursor) adapter.getItem(position);
    intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
    startActivity(intent);
}
}

有什么问题,为什么我会收到这个错误?

4

1 回答 1

3

将您的列表 ID 更改为@android:id/list. ListActivity需要ListView有这样的身份证。

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
于 2013-03-09T14:45:50.207 回答