IllegalArgumentException:调用SimpleCursorAdaptor时,列'_id'不存在 [英] IllegalArgumentException: column '_id' does not exist when call to SimpleCursorAdaptor

查看:94
本文介绍了IllegalArgumentException:调用SimpleCursorAdaptor时,列'_id'不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为master的表,其中列 id name gender 指定

I have a table named "master" with columns id, name, surname, gender, and designation

当我触发查询以获取光标对象时, CursorAdapter 我获得:

When I fire off a query to get a Cursor object for a CursorAdapter I get:

IllegalArgumentException: column '_id' does not exist when call to CursorAdaptor 


b $ b

但是我没有名为_id的圆柱。

But I don't have a columen named "_id".

任何人都能告诉我为什么会出现这个错误?

Can anybody tell me why I am getting this error?

这是堆栈跟踪:

07-13 15:45:40.582: WARN/System.err(295): java.lang.IllegalArgumentException: column '_id' does not exist
07-13 15:45:40.592: WARN/System.err(295):     at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
07-13 15:45:40.592: WARN/System.err(295):     at android.widget.CursorAdapter.changeCursor(CursorAdapter.java:257)
07-13 15:45:40.602: WARN/System.err(295):     at com.praumtech.names4baby.ui.NamesListAdapter.setCursor(NamesListAdapter.java:63)
07-13 15:45:40.602: WARN/System.err(295):     at com.praumtech.names4baby.ui.BoysNamesListActivity.initNameList(BoysNamesListActivity.java:79)
07-13 15:45:40.602: WARN/System.err(295):     at com.praumtech.names4baby.ui.BoysNamesListActivity.onCreate(BoysNamesListActivity.java:49)
07-13 15:45:40.602: WARN/System.err(295):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
07-13 15:45:40.602: WARN/System.err(295):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
07-13 15:45:40.612: WARN/System.err(295):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
07-13 15:45:40.612: WARN/System.err(295):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
07-13 15:45:40.612: WARN/System.err(295):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
07-13 15:45:40.612: WARN/System.err(295):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-13 15:45:40.621: WARN/System.err(295):     at android.os.Looper.loop(Looper.java:123)
07-13 15:45:40.621: WARN/System.err(295):     at android.app.ActivityThread.main(ActivityThread.java:4203)
07-13 15:45:40.621: WARN/System.err(295):     at java.lang.reflect.Method.invokeNative(Native Method)
07-13 15:45:40.621: WARN/System.err(295):     at java.lang.reflect.Method.invoke(Method.java:521)
07-13 15:45:40.621: WARN/System.err(295):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
07-13 15:45:40.621: WARN/System.err(295):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
07-13 15:45:40.631: WARN/System.err(295):     at dalvik.system.NativeStart.main(Native Method)


推荐答案

因为 CursorAdapter 在它使用的表中必须有一个 _id 列。

This is happening because CursorAdapter must have an _id column in the table it is using.

使用Android应用程序中的数据库(SQLite),最好在所有表中添加一个名为_id的列,以便能够使用 CursorAdapter

With the Database(SQLite) in Android applications, it is better to add a column named _id" to all tables in order to be able to use CursorAdapter.

或者,您可以编写一个sql语句,如

Alternatively, you can write an sql statement like

select member_id as _id from member _table where ....." 

c $ c> Cursor 其中可以使用 CursorAdapter

in order to get a Cursor which may be used with CursorAdapter.

CursorAdaptor 文档


将数据从Cursor暴露给ListView小部件的适配器。
Cursor必须包含一个名为_id的列,否则此类将不起作用。

Adapter that exposes data from a Cursor to a ListView widget. The Cursor must include a column named "_id" or this class will not work."

这篇关于IllegalArgumentException:调用SimpleCursorAdaptor时,列'_id'不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆