當我試圖從我的數據庫中的信息到一個表,我得到這個錯誤:錯誤上的光標從數據庫SQLite的選擇時,
05-15 14:15:55.250: E/AndroidRuntime(28050): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Sofia.MemoryGame/com.Sofia.MemoryGame.SQLView}: android.database.sqlite.SQLiteException: no such column: KEY_ROWID: , while compiling: SELECT KEY_ROWID, KEY_Name, KEY_Score FROM ScoreList
這裏是我的代碼:
public String getData() {
Cursor c = myDataBase.query(DATABASE_TABEL, new String[] {KEY_ROWID, KEY_Name, KEY_Score}, null, null, null, null, null);
String result = "";
int iRow = c.getColumnIndex(KEY_ROWID);
int iName = c.getColumnIndex(KEY_Name);
int iScore = c.getColumnIndex(KEY_Score);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result = result + c.getString(iRow) + " " + c.getString(iName) + " " + c.getString(iScore) + "\n";
}
return result;
}
我收到光標上的錯誤。任何人都可以看到我做錯了什麼?
在這裏,我也是我創建TABEL代碼:
public static final String KEY_ROWID = "_id";
public static final String KEY_Name = "player_names";
public static final String KEY_Score = "player_score";
private static final String DATABASE_NAME = "HighScore";
private static final String DATABASE_TABEL = "ScoreList";
private static final int DATABASE_VERSION = 1;
private DbHelper myHelper;
private final Context myContext;
private SQLiteDatabase myDataBase;
private static class DbHelper extends SQLiteOpenHelper {
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
//Skapar tabellen
db.execSQL("CREATE TABLE " + DATABASE_TABEL + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_Name + " TEXT NOT NULL, " +
KEY_Score + " TEXT NOT NULL); "
);
}
感謝。
請加上數據庫結構。 – Ivan