无法从游标窗口(Android)读取第0行第1列

无法从游标窗口(Android)读取第0行第1列,android,database,sqlite,Android,Database,Sqlite,我在MySQLiteHelper.java中的onCreate()方法中创建了一个类似于Players的表: String CREATE_PLAYERS_TABLE = "CREATE TABLE Players (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, password TEXT, score INTEGER)"; db.execSQL(CREATE_PLAYERS_TABLE); 我在同一个类中有一个upda

我在MySQLiteHelper.java中的onCreate()方法中创建了一个类似于
Players
的表:

String CREATE_PLAYERS_TABLE = "CREATE TABLE Players 
(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, password TEXT, score INTEGER)";

db.execSQL(CREATE_PLAYERS_TABLE);
我在同一个类中有一个update方法,如:

public int PlayerUpdate(Player PL) {

    // 1. get reference to writable DB
    SQLiteDatabase db = this.getWritableDatabase();

    // 2. create ContentValues to add key "column"/value
    ContentValues values = new ContentValues();
    values.put("name", PL.getName());
    values.put("password", PL.getPassword());
    values.put("score", PL.getScore());

    // 3. updating row
    int i = db.update(TABLE_Players, // table
            values, // column/value
            KEY_ID + " = ?", // selections
            new String[] { String.valueOf(PL.getId()) }); // selection args

    // 4. close
    db.close();

    return i;
}
当我调用函数将
score
变量更改为:

public void scoreUp() {
    helper.PlayerUpdate(new Player(player_name,player_password,player_score+5));
}
public void scoreDown() {
    helper.PlayerUpdate(new Player(player_name,player_password,player_score-5));
}
我得到一个logcat错误,如:

Failed to read row 0, column 1 from a CursorWindow which has 1 rows, 1 columns.
FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow.  
Make sure the Cursor is initialized correctly before accessing data from it.
谢谢

解决了的:
另一个查询导致了这个特定的异常,我发现了。

异常来自访问游标列,而您发布的代码没有显示这一点


但是,列索引从0开始,因此要以字符串形式访问第一列值,请使用
getString(0)
而不是
getString(1)

是的,您是对的。还有一件事导致了异常,我发现了这一点。谢谢你的帮助。