即使调用.moveToFirst(),SQL游标索引也不会移动到第一个

时间:2013-11-22 01:03:08

标签: android database cursor

嗨我一直在寻找这个问题很长一段时间我现在得到这个“ android.database.CursorIndexOutOfBoundsException:索引-1请求,大小为0” 所以我做的是我调用moveToFirst并记录它是否没有移动到第一个

public void addImg(String playerName, String imgPath){
        Cursor c = db.rawQuery(" SELECT " + PLAYER_ID + " FROM " + PLAYER_TBL + " WHERE " + PLAYER_NAME + "='" + playerName + "'", null);
        c.moveToFirst();
        if(c.moveToFirst()){
           int pathIndex = c.getColumnIndex(PLAYER_ID);
           int playerId = c.getInt(pathIndex);
           ContentValues image = new ContentValues();
           image.put(PLAYER_IMG_ID, playerId);
           image.put(PLAYER_IMG_PATH, imgPath);
           db.insert(PLAYER_IMG_TBL, null, image);
       } else {
           Log.v("test", "not move to first");
       }

  }

但是它仍然没有进入if语句,它仍然在其他...任何提示或帮助将非常感谢..谢谢:))

0 个答案:

没有答案
相关问题