列不存在错误

发布于 2024-10-21 08:47:07 字数 1288 浏览 1 评论 0原文

我正在开发一个使用三列数据库的应用程序。以下是我的创建语句:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

做个ˇ局外人 2024-10-28 08:47:07

您提供的代码看起来没问题。所以我怀疑你之前错过了一些事情,所以你的数据库确实没有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.

得不到的就毁灭 2024-10-28 08:47:07

像这样创建数据库,

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)";

请注意列名之间的空格分隔,并注意分号 (;) 已被删除。

create your database like this

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)";

Note the space separation between the column names and notice that the semicolon (;) has been removed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文