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

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

问题描述

我有一个表名为大师的列 ID 名称性别指定

当我火了一个查询,以获得光标对象一个的CursorAdapter 我得到:

 抛出:IllegalArgumentException:列'_id'不存在,当调用CursorAdaptor
 

但我没有columen名为_id。

谁能告诉我为什么我收到这个错误?

下面是堆栈跟踪:

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

解决方案

这是发生,因为的CursorAdapter 必须有一个 _id 列在它正在使用的表

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

另外,您也可以编写

SQL语句

 会员_table选择member_id作为_id的地方......
 

为了获得光标可与的CursorAdapter 使用。

这是 CursorAdaptor 指定的的文档

  

适配器从一个游标到ListView控件公开数据。该   光标必须包含一个名为_id列或这个类是行不通的。

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

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 

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

Can anybody tell me why I am getting this error?

Here is the stack trace:

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)

解决方案

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

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.

Alternatively, you can write an sql statement like

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

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

This is specified in CursorAdaptor's documentation:

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:列'_id'不存在,当调用SimpleCursorAdaptor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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