【发布时间】:2018-07-01 05:01:27
【问题描述】:
我正在开发一个带有 SQLite 数据库的 Android 应用程序。它记录交易。 transactions 表有以下列:
idTransaction INTEGER NOT NULL PRIMARY KEY AUTOINCREMENTdate DATE NOT NULLtype INT NOT NULLdetails VARCHAR(100) NOT NULLnotes VARCHAR(300) NOT NULLamount DOUBLE NOT NULLaccount INT NOT NULLcategory INT NOT NULL
我还做了一个方法来获取所有事务的游标:
// Select all Transactions
protected Cursor getTransactions() throws SQLException {
Cursor mCursor = null;
String[] colums = new String[]{"idTransaction", "date", "type", "details", "notes", "amount", "account", "category"};
mCursor = this.getReadableDatabase().query("Transactions", colums, null, null, null, null, "name ASC");
return mCursor;
}
在其他类中,我创建了一个方法来移动光标,当我调用 getTransactions() 方法时。
但异常发生在这一行:
mCursor = this.getReadableDatabase().query("Transactions", colums, null, null, null, null, "name ASC");
android.database.sqlite.SQLiteException: no such column: name(Sqlite code 1): , while compile: SELECT idTransaction, date, type, details, notes, amount, account, category FROM Transactions ORDER BY name ASC,(操作系统错误 - 2:没有这样的文件或目录)
我检查了表名和所有列名。我删除并重新安装了该应用程序,但我不知道为什么会发生异常。
【问题讨论】:
-
您列出了 8 列,其中没有一个称为
name,并且您要求按name升序排序(这就是"name ASC"的意思),那么您为什么会因为它失败而感到困惑“没有这样的专栏:name"?错误信息说明了一切。
标签: java android sqlite exception