我试图使用光标从我的数据库中获取一些值。我的问题是,当我尝试从我的数据库中获取值时,我的光标超出了界限。我确定我想要的值存在于数据库中,因为我有其他方法可以获得这些值。我想从中获得价值COLUMN_FIELDS_PARAMETER
日志猫:
05-09 11:24:17.872: E/AndroidRuntime(4113): FATAL EXCEPTION: main
05-09 11:24:17.872: E/AndroidRuntime(4113): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
05-09 11:24:17.872: E/AndroidRuntime(4113): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:424)
这是我的代码:放置值:
public void putParameters(int[] parameters, String exercise) {
String parametersList = "";
for(int i = 0; i < parameters.length; i++){
if (parameters[i] != 0)
{
parametersList = parametersList + " " + parameters[i];
}
}
ContentValues cv = new ContentValues();
cv.put(COLUMN_FIELDS_PARAMETER, parametersList);
cv.put(COLUMN_EXERCISE, exercise);
String whereClause = COLUMN_FIELDS_PARAMETER + "= ? and " + COLUMN_EXERCISE + "= '" + exercise + "'";
String[] columns = new String[]{COLUMN_EXERCISE, COLUMN_FIELDS_PARAMETER};
Cursor c = ourDatabase.query(TABLE_NAME, columns, whereClause , null, null, null, null, null);
if(c == null)
ourDatabase.insert(TABLE_NAME, null, cv);
else
ourDatabase.update(TABLE_NAME, cv, whereClause, null);
}
public String getParameters(String exercise){
String foo = "";
String whereClause = COLUMN_FIELDS_PARAMETER + "= ? and " + COLUMN_EXERCISE + "= '" + exercise + "'";
String[] columns = new String[]{COLUMN_EXERCISE, COLUMN_FIELDS_PARAMETER};
Cursor c = ourDatabase.query(TABLE_NAME, columns, whereClause , null, null, null, null);
int parameter = c.getColumnIndex(COLUMN_FIELDS_PARAMETER);
if (c != null)
{
c.moveToFirst();
foo = c.getString(parameter);
return foo;
}
return foo;
}