Android 栏目‘_id’不存在
以前,我通过放置 null 来选择所有内容,但出现错误,抱怨它的行太多,因此我尝试获取显示名称、联系人 ID 和电话号码的投影,但出现以下错误: “列 '_id' 不存在”
这是代码:
final String[] projection = { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.CONTACT_ID };
Cursor cur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,
"LENGTH(" + ContactsContract.CommonDataKinds.Phone.NUMBER
+ ") >= 8 ) GROUP BY ("
+ ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, null,
sortOrder);
但错误指向我的自定义适配器中的这一行
super(context, layout, c, from, to);
需要帮助!谢谢!
Previously I selected everything by putting a null, but i get an error complaining that it has too many rows, so I'm trying to get a projection of the display name, contact id and phone number but getting the following error:
"column '_id' does not exist"
Here's the code:
final String[] projection = { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.CONTACT_ID };
Cursor cur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,
"LENGTH(" + ContactsContract.CommonDataKinds.Phone.NUMBER
+ ") >= 8 ) GROUP BY ("
+ ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, null,
sortOrder);
But the error points to this line in my customadapter
super(context, layout, c, from, to);
Need help! Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
BaseColumns._ID
添加到您的投影阵列。Add
BaseColumns._ID
to your projection array.android 需要 _id 列,因此请在查询中包含带有私钥的列。
您可以使用以下内容重命名结果列:
“select PRIMARYKEYCOLUMN as _id,BLA,BLUBB from TABLE”
android needs the _id column, so include your column with private key in your query.
you can rename the result column with something like this:
"select PRIMARYKEYCOLUMN as _id,BLA,BLUBB from TABLE"
查看您的查询。您可能会错误地写column_id代替contact_id,否则它不会显示这种类型的错误。
See your query. You may write column_id in place of contact_id by mistake else it will not show this type error..