我正在使用一个使用三列数据库的应用程序。以下是我的创建声明:
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);
所以,根据这一点,似乎'wins'列在那里,但我仍然收到错误。知道为什么会这样吗?
答案 0 :(得分:0)
您提供的代码看起来不错。所以我怀疑你错过了之前的,所以你的数据库确实没有wins
列。检查如何创建数据库。
答案 1 :(得分:0)
像这样创建你的数据库
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)";
请注意列名称之间的空格分隔,并注意分号(;)已被删除。