Xamarin.Android 使用 SQLite 出现 Index -1 requested, with a size of 10 异常
生活随笔
收集整理的這篇文章主要介紹了
Xamarin.Android 使用 SQLite 出现 Index -1 requested, with a size of 10 异常
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
異常:?Android.Database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 10
此錯誤是數據返回到ICursor無法確定獲取列的索引,那么需要加上一下代碼即可。
if (i == 0) //確定游標位置 {ic.MoveToFirst(); } else {ic.MoveToNext(); }完整代碼Demo:
/// <summary> /// 查詢數據 /// </summary> void QueryData() {ICursor ic = Localhost_DataBase.Query("tb_person", null, null, null, null, null, null);for (int i = 0; i < ic.Count; i++){if (i == 0) //確定游標位置 {ic.MoveToFirst();}else{ic.MoveToNext();}person = new Person();person.Id = ic.GetString(ic.GetColumnIndex("Id"));person.Name = ic.GetString(ic.GetColumnIndex("name"));person.Age = ic.GetString(ic.GetColumnIndex("age"));person.Sex= ic.GetString(ic.GetColumnIndex("sex"));person.IdCard = ic.GetString(ic.GetColumnIndex("idcard")); list.Add(person); }lv_Person.Adapter = new ListViewAdapter(this, list); }?
轉載于:https://www.cnblogs.com/swjian/p/9360603.html
總結
以上是生活随笔為你收集整理的Xamarin.Android 使用 SQLite 出现 Index -1 requested, with a size of 10 异常的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: eclipse的操作
- 下一篇: Java学习之路(七):泛型