Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7416873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:35:08+00:00 2026-05-29T07:35:08+00:00

I got a database called test_database. And I got a table called tbl_marks .

  • 0

I got a database called test_database.
And I got a table called tbl_marks.
In tbl_marks there are following rows:

  • _id
  • name
  • subid
  • gewicht
  • datum

There are 4 entries. two with subid 1 and the other 2 with subid 2.

Now I like to do following:

SELECT * FROM tbl_marks WHERE subid = 1;

So finally I like to list all marks with subid 1, 2, 3 or what ever in a listview.

How can I do that by cursor?

I was trying to learn it by a tutorial but it failed…

Higherpass Android Tutorial Accessing-Data-With-Android-Cursors

Anddev Working with the sqlite database – Cursors

Code: The commented part is what I got before (it listed everything)

private void fillData() {
    // Get all of the notes from the database and create the item list

    mDbHelper.open_database_rw();
    Cursor mCursor = db.rawQuery("SELECT _id, subid, name, mark, gewicht, datum FROM tbl_marks ORDER BY subid;", null);
    startManagingCursor(mCursor);
    if (mCursor != null) {
         int intName = mCursor.getColumnIndexOrThrow("subid");

          do {
              teststring = mCursor.getString(intName);

              String[] from = new String[] { dbHelper.KEY_NAME_MARKS, dbHelper.KEY_MARK_MARKS, dbHelper.KEY_GEWICHT_MARKS, dbHelper.KEY_DATUM_MARKS};
              int[] to = new int[] {R.id.txt_marks_row, R.id.txt_note, R.id.txt_gewicht, R.id.txt_datum};


              SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.show_marks, mCursor, from, to);
              setListAdapter(notes);
          } while (mCursor.moveToNext());

    }

LogCat says that the column subid does not exists. But it’s there and the db has been opened.

02-07 11:30:00.500: D/dalvikvm(9913): GC_EXTERNAL_ALLOC freed 54K, 50% free 2694K/5379K, external 0K/0K, paused 56ms
02-07 11:30:00.535: D/dalvikvm(9913): GC_EXTERNAL_ALLOC freed 4K, 50% free 2698K/5379K, external 13K/523K, paused 27ms
02-07 11:30:10.457: D/AndroidRuntime(9913): Shutting down VM
02-07 11:30:10.457: W/dalvikvm(9913): threadid=1: thread exiting with uncaught exception (group=0x40235568)
02-07 11:30:10.457: E/AndroidRuntime(9913): FATAL EXCEPTION: main
02-07 11:30:10.457: E/AndroidRuntime(9913): java.lang.RuntimeException: Unable to start activity ComponentInfo{test.marco.notenha/test.marco.notenha.mark}: java.lang.IllegalArgumentException: column 'subid' does not exist
02-07 11:30:10.457: E/AndroidRuntime(9913):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1664)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1680)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at android.os.Looper.loop(Looper.java:130)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at android.app.ActivityThread.main(ActivityThread.java:3703)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at java.lang.reflect.Method.invokeNative(Native Method)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at java.lang.reflect.Method.invoke(Method.java:507)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at dalvik.system.NativeStart.main(Native Method)
02-07 11:30:10.457: E/AndroidRuntime(9913): Caused by: java.lang.IllegalArgumentException: column 'subid' does not exist
02-07 11:30:10.457: E/AndroidRuntime(9913):     at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at test.marco.notenha.mark.fillData(mark.java:180)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at test.marco.notenha.mark.onCreate(mark.java:70)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-07 11:30:10.457: E/AndroidRuntime(9913):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1628)
02-07 11:30:10.457: E/AndroidRuntime(9913):     ... 11 more

That’s line 180: int intName = mCursor.getColumnIndexOrThrow(“subid”);

02-07 11:52:26.304: D/dalvikvm(10075): GC_EXTERNAL_ALLOC freed 48K, 50% free 2694K/5379K, external 0K/0K, paused 38ms
02-07 11:52:26.339: D/dalvikvm(10075): GC_EXTERNAL_ALLOC freed 4K, 50% free 2698K/5379K, external 13K/523K, paused 30ms
02-07 11:52:29.433: D/AndroidRuntime(10075): Shutting down VM
02-07 11:52:29.433: W/dalvikvm(10075): threadid=1: thread exiting with uncaught exception (group=0x40235568)
02-07 11:52:29.437: E/AndroidRuntime(10075): FATAL EXCEPTION: main
02-07 11:52:29.437: E/AndroidRuntime(10075): java.lang.RuntimeException: Unable to start activity ComponentInfo{test.marco.notenha/test.marco.notenha.mark}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 3
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1664)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1680)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.os.Looper.loop(Looper.java:130)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.app.ActivityThread.main(ActivityThread.java:3703)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at java.lang.reflect.Method.invokeNative(Native Method)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at java.lang.reflect.Method.invoke(Method.java:507)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at dalvik.system.NativeStart.main(Native Method)
02-07 11:52:29.437: E/AndroidRuntime(10075): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 3
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at test.marco.notenha.mark.fillData(mark.java:183)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at test.marco.notenha.mark.onCreate(mark.java:70)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-07 11:52:29.437: E/AndroidRuntime(10075):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1628)
02-07 11:52:29.437: E/AndroidRuntime(10075):    ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:35:10+00:00Added an answer on May 29, 2026 at 7:35 am

    The “subid” column must be in the SELECT column list in order for the mCursor.getColumnIndexOrThrow(“subid”) call to return it:

    SELECT _id, name, mark, gewicht, datum, subid FROM tbl_marks ORDER BY subid;
    

    Edit:

    Now you need to call mCursor.moveToFirst() and check that it returns “true” (i.e. the result list is not empty). See this question. As an example:

    if (mCursor != null && mCursor.moveToFirst()) {
        int intName = mCursor.getColumnIndexOrThrow("subid");
        do {
              teststring = mCursor.getString(intName);
    
              ...
        } while (mCursor.moveToNext());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a database table called servers with three columns 'id', 'name', and 'votes'.
I've got a database table called 'mesg' with the following structure: receiver_id | sender_id
I've got a database table with at least three rows in it. From php,
I've got a (SQL Server) database table called Category. And another database table called
I have a database table called settings, and in that table I've got 2
I've an object which is called Uczestnik which just got saved to database var
Say you've got a database like this: books ----- id name And you wanted
I've got a categories table, and sub-category tables 3 levels deep (in the database
I've got an SQL Server database, which has a table containing a number of
I've got a table shop_categories with a field called category_is_hidden which is defined as:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.