在ListView中强制关闭错误

时间:2011-05-26 16:29:03

标签: android listview

我使用ListView对我的应用程序有一个强制关闭问题。只有当我使用ListActivity而不是Activity时,才会出现此问题。奇怪的是,我有另一个类完全相同的东西,但只是与数据库中的另一个表,它工作正常。我试图删除课堂上的所有内容,只显示视图,但我仍然关闭了力量。

我在网站上发现了一些类似的问题,但答案对我不起作用。

任何人都知道我做错了什么? - 任何帮助非常感谢。

我的xml文件:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">
<ListView android:id="@+id/android:list" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
<TextView android:id="@+id/android:empty" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="No recipes!" /> 
</TableLayout>

我的班级:

public class RecipesAlphabet extends ListActivity {

private GroceryDbAdapter mDbHelper;


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.alphabetical);

    mDbHelper = new GroceryDbAdapter(this);
    mDbHelper.open();
    fillRecipes();
    mDbHelper.close();
    registerForContextMenu(getListView());
    } 
private void fillRecipes() {
    Cursor recipeCursor = mDbHelper.fetchAllRecipes();
    startManagingCursor(recipeCursor);

    String[] from = new String[] {GroceryDbAdapter.KEY_RECIPE};
    int[] to = new int[] {R.id.text1};

    SimpleCursorAdapter recipes = new SimpleCursorAdapter(this, R.layout.groceries_row, recipeCursor, from, to);
    setListAdapter(recipes);

}
}

Log Cat:

05-26 19:00:23.864: DEBUG/AndroidRuntime(401): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
05-26 19:00:23.864: DEBUG/AndroidRuntime(401): CheckJNI is ON
05-26 19:00:24.134: DEBUG/AndroidRuntime(401): --- registering native functions ---
05-26 19:00:25.454: DEBUG/AndroidRuntime(401): Shutting down VM
05-26 19:00:25.464: DEBUG/dalvikvm(401): Debugger has detached; object registry had 1 entries
05-26 19:00:25.475: INFO/AndroidRuntime(401): NOTE: attach of thread 'Binder Thread #3' failed
05-26 19:00:26.154: DEBUG/AndroidRuntime(415): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
05-26 19:00:26.154: DEBUG/AndroidRuntime(415): CheckJNI is ON
05-26 19:00:26.394: DEBUG/AndroidRuntime(415): --- registering native functions ---
05-26 19:00:27.294: INFO/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.android.aqeel.grocerylisttest/.Main }
05-26 19:00:27.524: DEBUG/AndroidRuntime(415): Shutting down VM
05-26 19:00:27.564: DEBUG/dalvikvm(415): Debugger has detached; object registry had 1 entries
05-26 19:00:27.634: INFO/AndroidRuntime(415): NOTE: attach of thread 'Binder Thread #3' failed
05-26 19:00:27.694: INFO/ActivityManager(58): Start proc com.android.aqeel.grocerylisttest for activity com.android.aqeel.grocerylisttest/.Main: pid=422 uid=10042 gids={}
05-26 19:00:29.274: INFO/ActivityManager(58): Displayed activity com.android.aqeel.grocerylisttest/.Main: 1755 ms (total 257143 ms)
05-26 19:00:34.543: DEBUG/dalvikvm(124): GC_EXPLICIT freed 252 objects / 11688 bytes in 209ms
05-26 19:00:40.393: INFO/ActivityManager(58): Starting activity: Intent { cmp=com.android.aqeel.grocerylisttest/.Recipes }
05-26 19:00:40.454: DEBUG/dalvikvm(58): GREF has increased to 301
05-26 19:00:41.043: INFO/ActivityManager(58): Displayed activity com.android.aqeel.grocerylisttest/.Recipes: 598 ms (total 598 ms)
05-26 19:00:42.453: INFO/ActivityManager(58): Starting activity: Intent { cmp=com.android.aqeel.grocerylisttest/.RecipesAlphabet }
05-26 19:00:42.563: DEBUG/AndroidRuntime(422): Shutting down VM
05-26 19:00:42.563: WARN/dalvikvm(422): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-26 19:00:42.603: ERROR/AndroidRuntime(422): FATAL EXCEPTION: main
05-26 19:00:42.603: ERROR/AndroidRuntime(422): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.aqeel.grocerylisttest/com.android.aqeel.grocerylisttest.RecipesAlphabet}: java.lang.IllegalArgumentException: column '_id' does not exist
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.os.Looper.loop(Looper.java:123)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at java.lang.reflect.Method.invokeNative(Native Method)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at java.lang.reflect.Method.invoke(Method.java:521)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at dalvik.system.NativeStart.main(Native Method)
05-26 19:00:42.603: ERROR/AndroidRuntime(422): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.widget.CursorAdapter.init(CursorAdapter.java:111)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.widget.CursorAdapter.<init>(CursorAdapter.java:90)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:47)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:84)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at com.android.aqeel.grocerylisttest.RecipesAlphabet.fillRecipes(RecipesAlphabet.java:32)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at com.android.aqeel.grocerylisttest.RecipesAlphabet.onCreate(RecipesAlphabet.java:21)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-26 19:00:42.603: ERROR/AndroidRuntime(422):     ... 11 more
05-26 19:00:42.714: DEBUG/dalvikvm(422): GC_FOR_MALLOC freed 5728 objects / 343136 bytes in 110ms
05-26 19:00:42.733: WARN/ActivityManager(58):   Force finishing activity com.android.aqeel.grocerylisttest/.RecipesAlphabet
05-26 19:00:42.753: WARN/ActivityManager(58):   Force finishing activity com.android.aqeel.grocerylisttest/.Recipes
05-26 19:00:43.253: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{450e6a18 com.android.aqeel.grocerylisttest/.RecipesAlphabet}
05-26 19:00:44.774: INFO/Process(422): Sending signal. PID: 422 SIG: 9
05-26 19:00:44.827: INFO/WindowManager(58): WIN DEATH: Window{450df0f8 com.android.aqeel.grocerylisttest/com.android.aqeel.grocerylisttest.Main paused=false}
05-26 19:00:44.827: INFO/ActivityManager(58): Process com.android.aqeel.grocerylisttest (pid 422) has died.
05-26 19:00:44.844: INFO/WindowManager(58): WIN DEATH: Window{450e3c80 com.android.aqeel.grocerylisttest/com.android.aqeel.grocerylisttest.Recipes paused=true}
05-26 19:00:44.895: INFO/UsageStats(58): Unexpected resume of com.android.launcher while already resumed in com.android.aqeel.grocerylisttest
05-26 19:00:45.753: WARN/InputManagerService(58): Got RemoteException sending setActive(false) notification to pid 422 uid 10042

1 个答案:

答案 0 :(得分:3)

检查表的创建,因为光标正在查找新表中不存在的列:

Caused by: java.lang.IllegalArgumentException: column '_id' does not exist

您需要重命名主键列“_id