2

データベース クラス

public boolean Permissions(String modulename) {
    int createable, updateable;
    Cursor cursor = db.rawQuery("select * from " + "moduleDesc" + " where "
            + "name" + "='" + modulename + "'", null);
    if (cursor.getCount() > 0);
        {
        createable = cursor.getInt(cursor.getColumnIndex("createable"));
        updateable = cursor.getInt(cursor.getColumnIndex("updateable"));
        cursor.close();
    }
    if ((createable == 1) && (updateable == 1)) {
        return true;

    } else {
        return false;
    }
}

私が取得しているエラーは、作成可能なカーソルインデックスアウトオブバウンドです cursor.getInt(cursor.getColumnIndex("createable")); が、カーソルにはまだ値がありますが、このエラーが発生します!!! 事前に感謝

4

3 に答える 3

1

それよりも:

  if (cursor.getCount() > 0) { 
      //Code here
  }

使用する

  if (cursor.moveToFirst()) { 
      //Code here
  }

これでおそらく問題が解決します。

于 2012-07-27T12:17:53.177 に答える
1
Try this solution 

public boolean Permissions(String modulename) {
int createable, updateable;
Cursor cursor = db.rawQuery("select * from " + "moduleDesc" + " where "
        + "name" + "='" + modulename + "'", null);
if (cursor.getCount() > 0);
    {
    cursor.MoveToFirst();//use this if cursor count is 1 else use while loop 
    //while (cursor.MoveToNext){
    createable = cursor.getInt(cursor.getColumnIndex("createable"));
    updateable = cursor.getInt(cursor.getColumnIndex("updateable"));
    //}
    cursor.close();
}
if ((createable == 1) && (updateable == 1)) {
    return true;

} else {
    return false;
}

}

于 2012-07-27T12:19:56.617 に答える
0

適切なカーソルを閉じます。

public boolean Permissions(String modulename) {
    Cursor cursor = db.rawQuery("select * from " + "moduleDesc" + " where "
            + "name" + "='" + modulename + "'", null);
    if (cursor != null) {
        try {
           if (cursor.moveToFirst()) {
               int createable = cursor.getInt(cursor.getColumnIndex("createable"));
               int updateable = cursor.getInt(cursor.getColumnIndex("updateable"));
               return (createable == 1) && (updateable == 1);
           }
        } finally {
            cursor.close();
        }
    }
   return false;
}
于 2012-07-27T12:22:07.473 に答える