Android Question SQL Cursor Error

Discussion in 'Android Questions' started by shashkiranr, Jun 28, 2015.

  1. shashkiranr

    shashkiranr Active Member Licensed User

    Hi All,

    I am getting the below error when i read data from the cursor when its position is at 10th row. There are totally 20 rows. It works from 0 to 9 . I checked the DB and it is fine.

    java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
    For i = 0 To cu.RowCount-1
    Dim detail As Ebook
            cu.Position = i
            detail.ID = cu.GetInt(
    Any suggestions of how to solve will be very helpful.

  2. mangojack

    mangojack Well-Known Member Licensed User

    are you sure the db is initialized ?
  3. shashkiranr

    shashkiranr Active Member Licensed User

    Yes. The rows from 0 to 9 can be read easily. its in a for loop.
  4. DonManfred

    DonManfred Expert Licensed User

    No. It stops reading the first (0).

  5. shashkiranr

    shashkiranr Active Member Licensed User

    I really dont understand. When the position of the cursor goes from 9 to 10, why will it again go to the first row(0) ?
  6. LucaMs

    LucaMs Expert Licensed User

    what are you talking about???
    Last edited: Jun 28, 2015
  7. shashkiranr

    shashkiranr Active Member Licensed User

  8. cimperia

    cimperia Active Member Licensed User

    Just a thought. Is the variable i dim'd at all or is it relying on default? Try to dim it as an integer or a long and see whether it makes any difference?
  9. shashkiranr

    shashkiranr Active Member Licensed User

    Here is the full code. I still am not able to solve getting the same error when position is 10. I opened the same DB with ERel Sqlite Viwer and its working. !! :(

    If Not(File.Exists(File.DirInternal, "ebook.db3")) Then
    File.Copy(File.DirAssets, "ebook.db3"File.DirInternal, "ebook.db3")
    File.Delete(File.DirInternal, "ebook.db3")
    File.Copy(File.DirAssets, "ebook.db3"File.DirInternal, "ebook.db3")
    End If
    Dim cu As Cursor
        cu = sq.ExecQuery(
    "SELECT * FROM Ebook")
    For i = 0 To cu.RowCount-1
    Dim detail As Ebook
            cu.Position = i
            detail.ID = cu.GetInt(
            detail.Publisher = cu.GetString(
            detail.Title = cu.GetString(
            detail.Category = cu.GetString(
            detail.Downloads = cu.Getint(
            detail.Likes = cu.GetInt(
            detail.Comments = cu.GetInt(
            detail.Author = cu.GetString(
            detail.Summary = cu.GetString(
            detail.price = cu.GetString(
    DateTime.DateFormat = "MM/dd/yyyy"
    Dim DateDB As Long = DateTime.DateParse(cu.GetString("Date"))
            detail.Date = DateDB
    Dim Bmp As Bitmap
    Dim binImage() As Byte, Flux As InputStream
            binImage = cu.GetBlob(
    0, binImage.Length)
            detail.Image = Bmp
  10. shashkiranr

    shashkiranr Active Member Licensed User

    Got the error. Prob is my database size is huge so the cursor is retrieving all the data hence this error. !! Dumb move !! The below link will explain.

    Edit : I have used Select * , so this will retrieve all the records and the size is more. For anyone who gets this error , check your sql query.

    Took me 3 hrs to figure out :(

    Last edited: Jun 28, 2015
    cimperia likes this.
  11. cimperia

    cimperia Active Member Licensed User

    I think the problem is the size of the thumbnails. If you were to query the database without it, I'm pretty sure there would be no error.

    Thank you for reporting the solution.
  12. lkching7

    lkching7 Member Licensed User

    No Wonder... Thank You For Your Research...
  13. Mahares

    Mahares Well Known Member Licensed User

    1. I have tested your code and if you issue a LIMIT 10 at the end of your SQL statement, it will display the first 10 records without any issues.
    2. As @cimperia mentioned, the BLOB field data is what is slowing you down. If you remove the Thumbnail field from the query, it will run smoothly for all records.
    3. You also need to dim the detail inside the for i =0 to......loop like the below. Otherwise you are creating the same object and adding it to the list every time:
    For i = 0 To cu.RowCount-1
    Dim detail As Ebook
    eps and cimperia like this.
  14. shashkiranr

    shashkiranr Active Member Licensed User

    @Mahares There was a image which was 2.2MB. Thats why it was failing. Still SELECT * is not recommended. Thank you for your effort :)
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice