2013-03-09 140 views
0

我是一名android初學者,我嘗試創建一個Employee Directory。但每次當我運行該項目時我收到此錯誤: enter image description here致命異常:主要android

enter image description here

這是邁的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> 

這裏是麥java的CLASE:

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); 
} 
} 

問題是什麼,並且我收到這個錯誤?

+1

複製並粘貼錯誤堆棧跟蹤。而不是快照。 – SudoRahul 2013-03-09 14:45:31

回答

3

將您的列表ID更改爲@android:id/listListActivity要求ListView有這樣的id。

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