[英]Column does not exist Error
我正在使用使用三列數據庫的應用程序。 以下是我的create語句:
public static final String KEY_ID = "_id";
public static final String KEY_NAME = "name";
public static final String KEY_GAMES = "games";
public static final String KEY_WINS = "wins";
private static final String DATABASE_CREATE = "create table "
+ DATABASE_TABLE + " ("
+ KEY_ID + " integer primary key autoincrement, "
+ KEY_NAME + " text not null, "
+ KEY_GAMES + " integer, "
+ KEY_WINS + " integer);";
現在,我通過執行以下操作將數據庫中的數據映射到ListView:
Cursor notesCursor = mDbHelper.getAllEntriesCursor();
startManagingCursor(notesCursor);
String[] from = new String[]{DbAdapter.KEY_NAME, DbAdapter.KEY_WINS, DbAdapter.KEY_GAMES};
int[] to = new int[]{R.id.names, R.id.wins, R.id.games};
SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.win_games, notesCursor, from, to);
setListAdapter(notes);
當我運行時,出現以下錯誤:
java.lang.IllegalArgumentException: column 'wins' does not exist
當我通過命令行輸入仿真器並顯示數據庫的架構時,將顯示以下內容:
CREATE TABLE namesTable (_id integer primary key autoincrement, name text not null, games integer, wins integer);
因此,據此看來,“獲勝”列在那里,但我仍然收到錯誤。 知道為什么會這樣嗎?
像這樣創建數據庫
private static final String DATABASE_CREATE = "create table "
+ DATABASE_TABLE + " ("
+ KEY_ID + " integer primary key autoincrement,"
+ KEY_NAME + " text not null,"
+ KEY_GAMES + " integer,"
+ KEY_WINS + " integer)";
請注意列名稱之間的空格分隔,並注意已刪除分號(;)。
您提供的代碼看起來不錯。 因此,我懷疑您之前錯過了smth,因此您的DB確實沒有wins
專欄。 檢查如何創建數據庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.