Search code examples
androiddatabaseandroid-contentresolver

java.lang.ArrayIndexOutOfBoundsException: asked for back ref X but there are only 0 back refs


I'm doing some database work on Android, and get the following error when trying to insert a bunch of records using applyBatch.

java.lang.ArrayIndexOutOfBoundsException: asked for back ref 26 but there are only 0 back refs

What's causing this?


Solution

  • For me, it turns out that I was trying to insert a group of records using applyBatch, but one of the later records depended on an earlier record in the group being inserted correctly, which it wasn't (it failed).

    I identified the error by doing "applyBatch" with each of the ContentOperations, one at a time. Then i could easily see why it was failing.

    Note that this post was helpful in figuring out the problem.