亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嘗試從 SQLite DB 設置 checktextview 時出錯

嘗試從 SQLite DB 設置 checktextview 時出錯

當年話下 2023-09-13 15:27:09
我正在嘗試從 SQLite 數據庫獲取 checkTextView 狀態,但它導致應用程序崩潰。下面是實現的代碼: Cursor c = db.rawQuery("SELECT * FROM list", null); int foundIndex = c.getColumnIndex("found"); while (c != null) {      c.getString(foundIndex);      c.moveToNext(); } String[] foundList = new String[foundIndex]; arrayAdapter.notifyDataSetChanged(); for (String found : levelOneListList){      if (levelOneListList == foundList){          levelOneListView.setItemChecked(found.indexOf(foundIndex), true);      } }}它給出了這個錯誤:java.lang.RuntimeException:無法啟動活動 ComponentInfo{com.example.woodlandwanderer/com.example.woodlandwanderer.levelOneActivity}:android.database.CursorIndexOutOfBoundsException:請求索引 -1,大小為 0
查看完整描述

2 回答

?
九州編程

TA貢獻1785條經驗 獲得超4個贊

正如錯誤所示,您的光標大小為 0,并且您正在嘗試首先訪問。

在循環之前添加以下檢查。

if (c.moveToNext() && c.getCount()>0) {


查看完整回答
反對 回復 2023-09-13
?
開心每一天1111

TA貢獻1836條經驗 獲得超13個贊

像這樣讀取光標數據??雌饋砟愕墓鈽舜笮∈?0。


    if (c != null && c.moveToFirst()){

        do {


           int foundIndex = c.getColumnIndex("found");

           c.getString(foundIndex);


        } while (c.moveToNext());


      c.close(); // close your db cursor

    }


// list update and set checkbox value here


查看完整回答
反對 回復 2023-09-13
  • 2 回答
  • 0 關注
  • 92 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號