android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 3

       今天在写一个小项目的数据库部分的功能时,出现了一个这样的问题:java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=99, result=-1, data=Intent { (has extras) }} to activity {com.xxx.xxx/com.xxx.xxx.activity.XXXXActivity}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 3

       字面上是理解越界错误(实际就是),但是我自以为程序逻辑应该没有问题,那个地方应该有值的啊,后来发现,原来事实并不是我想的那样,确实发生了越界,具体的解决办法是通过循环来解决,while(cursor.moveToNext()){},我们不能主观的认为cursor有多少行,所以通过循环的方式来遍历是稳妥安全的方式。在遍历中,自然会找到我们要找到的数据。thanks~

原文地址:https://www.cnblogs.com/riskyer/p/3268475.html