【发布时间】:2011-03-22 12:36:59
【问题描述】:
我在使用记事本示例时遇到了问题。 这是来自 NotepadCodeLab/Notepadv1Solution 的代码:
String[] from = new String[] { NotesDbAdapter.KEY_TITLE };
int[] to = new int[] { R.id.text1 };
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
R.layout.notes_row, c, from, to);
这段代码似乎工作正常。但为了清楚起见,我运行了ADB 实用程序并运行 SQLite 3。我检查了架构如下:
sqlite> .schema
CREATE TABLE android_metadata (locale TEXT);
CREATE TABLE notes (_id integer primary key autoincrement, title text
not null, body text not null);
我觉得一切都很好。
现在开始我的应用程序,据我所知,它与 一些小的变化。我已经简化并简化了我的代码,但是 问题依然存在。
String[] from = new String[] { "x" };
int[] to = new int[] { R.id.x };
SimpleCursorAdapter adapter = null;
try
{
adapter = new SimpleCursorAdapter(this, R.layout.circle_row, cursor, from, to);
}
catch (RuntimeException e)
{
Log.e("Circle", e.toString(), e);
}
当我运行我的应用程序时,我得到一个 RuntimeException 和以下打印
在我的 Log.e() 声明中的 LogCat 中:
LogCat 消息:
java.lang.IllegalArgumentException:列“_id”不存在
所以,回到 SQLite 3 看看我的架构有什么不同:
sqlite> .schema 创建表 android_metadata(语言环境文本); CREATE TABLE circles(_id 整数主键自增,序列 整数,半径实数,x 实数,y 实数);
我看不出我是怎么错过“_id”的。
我做错了什么?
我的应用程序和记事本示例之间的不同之处在于 我首先使用 Eclipse 向导,而示例应用程序已经放在一起。是 我需要为新应用程序进行某种环境改变 使用 SQLite 数据库?
【问题讨论】:
-
您能否提供更多有关您如何创建游标以及您如何打开数据库的详细信息?
-
您是否从选择_ID 列返回?检查您的光标创建。