我在记事本示例中遇到了一些问题。 下面的代码从NotepadCodeLab/Notepadv1Solution:Android列'_id'不存在?
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);
}
当我运行我的应用程序,我得到了logcat的一个RuntimeException和下面的打印 从我Log.e()
声明:
logcat的消息:
java.lang.IllegalArgumentException异常:列' _id'不存在
所以,回到SQLite 3看看我的sc有什么不同hema:
sqlite> .schema CREATE TABLE android_metadata(locale TEXT); CREATE TABLE圈(_id整数主键自动增量,序列 整数,半径实数,x实数,y实数);
我不明白我是如何遗漏'_id'的。
我做错了什么?
有一两件事是我的应用程序和记事本实例之间的不同是 ,我开始使用Eclipse的 向导时,示例应用程序自带已经放在一起从头开始创建我的应用程序。 有一些环境变化需要我为新的应用程序 使用SQLite数据库吗?
你能提供你如何创建光标更多的细节可以发现,也许你是如何打开的数据库? – EboMike 2010-07-29 04:14:34
您是否从您选择的_ID列返回?检查你的光标创建。 – Pentium10 2010-07-29 08:51:14