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

  • Home
  • SEARCH
  • 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 8002949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:31:28+00:00 2026-06-04T16:31:28+00:00

I’m trying to fill up 10 textviews with data from my HighscoreDB. Every time

  • 0

I’m trying to fill up 10 textviews with data from my HighscoreDB. Every time my application’s game ends, the user is asked to store their score in the database, along with a name.
Then, I fill 10 textviews (actually 20, but there are 10 rows with name and score.). This used to work (when there were a few highscore records in HighscoreDB), but ever since I created a new emulator and thereby deleting all the highscore rows, I keep getting the
“android.database.CursorIndexOutOfBoundsException: Index x requested, with a size of x” error.
The x represents how many rows I currently have, for instance if I have 5 highscore rows in the DB, the error will be “Index 5 requested, with a size of 5” (found that out by trying out new ways to fix my problem but it remained, and I noticed that the index also increases).
Can anyone point out what I’m doing wrong or how tell me how to fix my code?

This is the code in my HighscoreActivity in which the highscores are put in the textviews:

                   db = (new HighscoreDB(this)).getWritableDatabase();
cursor = db.rawQuery("SELECT _id, name, score FROM highscore ORDER BY score DESC",  null);
                   cursor.moveToFirst();
             for (int i = 0; i < 10; i++) {



            TableRow row = (TableRow)mHighscoreTable.getChildAt(i+1);
            TextView tvName = (TextView)row.getChildAt(1);

            tvName.setText(cursor.getString(1));
            TextView tvScore = (TextView)row.getChildAt(2);

            tvScore.setText(Integer.toString(cursor.getInt(2)));


            cursor.moveToNext();



    }

The line “for (int i = 0; i < 10; i++) {” is because I only want to show 10 highscores at a time in the 10 rows of textviews.

This is how the table is made:

private static final String SCORE_TABLE_CREATE = "CREATE TABLE "
                                                 + SCORE_TABLE_NAME
                                                 + " (_id INTEGER PRIMARY KEY autoincrement, "
                                                 + "name TEXT NOT NULL, score INTEGER  NOT NULL)";

This was my latest error:

05-25 17:03:16.786: E/AndroidRuntime(780): FATAL EXCEPTION: main
05-25 17:03:16.786: E/AndroidRuntime(780): java.lang.RuntimeException: Unable to start activity ComponentInfo{be.michiel.test/be.michiel.test.HighscoreActivity}: android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.os.Looper.loop(Looper.java:123)
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.app.ActivityThread.main(ActivityThread.java:3683)
05-25 17:03:16.786: E/AndroidRuntime(780):  at java.lang.reflect.Method.invokeNative(Native Method)
05-25 17:03:16.786: E/AndroidRuntime(780):  at java.lang.reflect.Method.invoke(Method.java:507)
05-25 17:03:16.786: E/AndroidRuntime(780):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-25 17:03:16.786: E/AndroidRuntime(780):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-25 17:03:16.786: E/AndroidRuntime(780):  at dalvik.system.NativeStart.main(Native Method)
05-25 17:03:16.786: E/AndroidRuntime(780): Caused by: android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
05-25 17:03:16.786: E/AndroidRuntime(780):  at be.michiel.test.HighscoreActivity.onCreate(HighscoreActivity.java:79)
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-25 17:03:16.786: E/AndroidRuntime(780):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-25 17:03:16.786: E/AndroidRuntime(780):  ... 11 more

Please help me find my mistake. I’ve been trying to find out for a long time now.
Thanks in advance!

  • 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-06-04T16:31:30+00:00Added an answer on June 4, 2026 at 4:31 pm

    You should never do this without checking whether the next record is available or not. Try changing your code like below :

    db = (new HighscoreDB(this)).getWritableDatabase();
    cur = db.rawQuery("SELECT _id, name, score FROM highscore ORDER BY score DESC",  null);
    int noOfScorer=0;
    cur.moveToFirst();
        while ((!cur.isAfterLast())&&noOfScorer<11) 
        {
            noOfScorer++;
            TableRow row = (TableRow)mHighscoreTable.getChildAt(noOfScorer);
            TextView tvName = (TextView)row.getChildAt(1);
            TextView tvScore = (TextView)row.getChildAt(2);
    
            tvName.setText(cur.getString(1));
            tvScore.setText(Integer.toString(cur.getInt(2)));
    
            cur.moveToNext();
        }
    

    Hope this helps you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from

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.