Reputation: 43
I am having a force close problem with my application using ListView. The problem only occurs when I use ListActivity in stead of Activity. The wierd part is that I have another class which does exactly the same thing, but just with another table from the database and it is working fine. I tried to remove everything in my class and just display the view, but I still get the force close.
I found some simular questions on the site, but the answers did not work for me.
Anybody have any clue of what I am doing wrong? - Any help much appreciated.
My xml file:
<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>
My Class:
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
Upvotes: 1
Views: 983
Reputation: 40391
Check the creation of your tables, since your cursor is looking for a column that is not present in the new table:
Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
You need to rename your Primary Key column "_id
"
Upvotes: 3