標籤:fbo xamarin 圖片 bsp column ase person .com png
異常: 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);}
Xamarin.Android 使用 SQLite 出現 Index -1 requested, with a size of 10 異常