Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid, bind ListView to SQLite Database
    primarykey
    data
    text
    <p>I have an SQLiteDatabase helper, which returns a cursor with just the name column from a database:</p> <pre><code>public Cursor getNames() { Cursor cursor = db.query(TABLE_NAME, new String[] {NAME}, null, null, null, null, null); return cursor; } </code></pre> <p>I am trying to bind this cursor to a simple ListView contained in the Layout:</p> <pre><code>&lt;ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;/ListView&gt; </code></pre> <p>The java:</p> <pre><code> Cursor cursor = db.getNames(); startManagingCursor(cursor); ListAdapter adapter = new SimpleCursorAdapter ( this, android.R.layout.simple_list_item_1, cursor, new String[] {constants.NAME}, new int[] {android.R.id.text1} ); setListAdapter(adapter); </code></pre> <p>I've followed every tutorial I can find but the app still stops unexpectedly. Please tell me what I'm doing wrong! </p> <p>Here's the LOGCAT trace, hope thats what you needed:</p> <pre><code>12-03 17:18:41.557: E/AndroidRuntime(30413): FATAL EXCEPTION: main 12-03 17:18:41.557: E/AndroidRuntime(30413): java.lang.RuntimeException: Unable to start activity ComponentInfo{george.frost.YourCarbDatabase/com.android.CarbCount.Search}: java.lang.IllegalArgumentException: column '_id' does not exist 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.app.ActivityThread.access$1500(ActivityThread.java:121) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.os.Handler.dispatchMessage(Handler.java:99) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.os.Looper.loop(Looper.java:130) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.app.ActivityThread.main(ActivityThread.java:3701) 12-03 17:18:41.557: E/AndroidRuntime(30413): at java.lang.reflect.Method.invokeNative(Native Method) 12-03 17:18:41.557: E/AndroidRuntime(30413): at java.lang.reflect.Method.invoke(Method.java:507) 12-03 17:18:41.557: E/AndroidRuntime(30413): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 12-03 17:18:41.557: E/AndroidRuntime(30413): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 12-03 17:18:41.557: E/AndroidRuntime(30413): at dalvik.system.NativeStart.main(Native Method) 12-03 17:18:41.557: E/AndroidRuntime(30413): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.widget.CursorAdapter.init(CursorAdapter.java:111) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.widget.CursorAdapter.&lt;init&gt;(CursorAdapter.java:90) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.widget.ResourceCursorAdapter.&lt;init&gt;(ResourceCursorAdapter.java:47) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.widget.SimpleCursorAdapter.&lt;init&gt;(SimpleCursorAdapter.java:84) 12-03 17:18:41.557: E/AndroidRuntime(30413): at com.android.CarbCount.Search.onCreate(Search.java:42) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 12-03 17:18:41.557: E/AndroidRuntime(30413): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623) 12-03 17:18:41.557: E/AndroidRuntime(30413): ... 11 more </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload