列不存在错误
我正在开发一个使用三列数据库的应用程序。以下是我的创建语句:
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”列在那里,但我仍然收到错误。知道为什么会这样吗?
I am working on an application that uses a database with three columns. The following is my create statement:
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);";
Now, I am mapping the data in the database to a ListView by doing the following:
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);
When I run, the following error is given to me:
java.lang.IllegalArgumentException: column 'wins' does not exist
When I shell into the emulator via command line and display the schema of the database, the following is displayed:
CREATE TABLE namesTable (_id integer primary key autoincrement, name text not null, games integer, wins integer);
So, according to that, it appears that the 'wins' column is there, but I still receive the error. Any idea why this is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您提供的代码看起来没问题。所以我怀疑你之前错过了一些事情,所以你的数据库确实没有
wins
列。检查您如何创建数据库。The code you provided looks OK. So I suspect you missed smth before, so your DB really does not have
wins
column. Check how you create your DB.像这样创建数据库,
请注意列名之间的空格分隔,并注意分号 (;) 已被删除。
create your database like this
Note the space separation between the column names and notice that the semicolon (;) has been removed.