sam*_*met 2 database sqlite android
我创建了一个类似PlayersonTreate()方法的表,它位于MySQLiteHelper.java中:
String CREATE_PLAYERS_TABLE = "CREATE TABLE Players
(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, password TEXT, score INTEGER)";
db.execSQL(CREATE_PLAYERS_TABLE);
Run Code Online (Sandbox Code Playgroud)
我在同一个类中有一个更新方法,如:
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;
}
Run Code Online (Sandbox Code Playgroud)
当我调用函数来改变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));
}
Run Code Online (Sandbox Code Playgroud)
我收到一个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.
Run Code Online (Sandbox Code Playgroud)
谢谢.
还有另一个查询导致了这个特定的异常,我发现了.
| 归档时间: |
|
| 查看次数: |
2689 次 |
| 最近记录: |