Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

android CursorIndexOutOfBoundsException: Index 20

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having problems with my cursor for some reason it is producing the CursorIndexOutOfBoundException.
The error occurs on record 19 according to my counter variable. I belive the problem is occuring within these two method. I set the cursor to move to the first record which appears to work.
Although when I try and fetch the current position it returns a negative one. This is the method I used c.getPosition().





Here is my logcat

09-28 16:23:22.134: E/AndroidRuntime(530): FATAL EXCEPTION: main
09-28 16:23:22.134: E/AndroidRuntime(530): android.database.CursorIndexOutOfBoundsException: Index 20 requested, with a size of 20
09-28 16:23:22.134: E/AndroidRuntime(530): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:400)
09-28 16:23:22.134: E/AndroidRuntime(530): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
09-28 16:23:22.134: E/AndroidRuntime(530): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
09-28 16:23:22.134: E/AndroidRuntime(530): at alex.android.development.Basic_database_questionsActivity.DisplayRadioButton(Basic_database_questionsActivity.java:374)
09-28 16:23:22.134: E/AndroidRuntime(530): at alex.android.development.Basic_database_questionsActivity.nextRecord(Basic_database_questionsActivity.java:144)



Here is the main body of the code

 
Ranch Hand
Posts: 51
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi !

Maybe problem is in variable "counter," that has value equal 20. Your "coursor" has 20 elements counted from 0 - 19 .. so .. if you try to get element with index 20 you have exception.

Bye !
 
Happily living in the valley of the dried frogs with a few tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic