Android列‘_id’不存在嗎?我在記事本的例子中遇到了問題。下面是NotepadCodeLab/NotepAdvanc1S卷積的代碼: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);這段代碼似乎運(yùn)行良好。但我要澄清的是,我運(yùn)行了亞行工具并運(yùn)行SQLite 3。sqlitt>.schemaCREATE TABLE android_metadata (locale TEXT);CREATE TABLE notes (_id integer primary key autoincrement, title textnot null, body text not null);我覺得一切都很好?,F(xiàn)在來看我的應(yīng)用程序,據(jù)我所見,它基本上是一樣的,只是做了一些小改動(dòng)。我已經(jīng)簡化和簡化了我的代碼,但問題仍然存在。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);}當(dāng)我運(yùn)行我的應(yīng)用程序時(shí),我得到一個(gè)RuntimeException,并在logcat中從Log.e()聲明:logcat消息:java.lang.IllegalArgumentException:列‘_id’不存在因此,回到SQLite 3,看看我的模式有什么不同:模式創(chuàng)建表Android_元數(shù)據(jù)(地區(qū)文本);創(chuàng)建表圓(_id整數(shù)主鍵自動(dòng)增量、序列整數(shù)、半徑實(shí)數(shù)、x實(shí)、y實(shí));我不知道我怎么會(huì)錯(cuò)過‘_id’。我做錯(cuò)了什么?我的應(yīng)用程序和記事本示例之間的一個(gè)不同之處是,我使用Eclipse向?qū)念^開始創(chuàng)建應(yīng)用程序,而示例應(yīng)用程序已經(jīng)放在一起。對于使用SQLite數(shù)據(jù)庫的新應(yīng)用程序,是否需要進(jìn)行某種環(huán)境更改?
3 回答

慕碼人2483693
TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊
SQLiteDatabase db = mHelper.getReadableDatabase(); Cursor cur = db.rawQuery( "select rowid _id,* from your_table", null);

浮云間
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超4個(gè)贊
db.query(TABLE_USER, new String[] { "rowid _id", FIELD_USERNAME, }, FIELD_USERNAME + "=" + name, null, null, null, null);
- 3 回答
- 0 關(guān)注
- 335 瀏覽
添加回答
舉報(bào)
0/150
提交
取消