Android 栏目‘_id’不存在

发布于 2024-12-02 17:44:04 字数 760 浏览 0 评论 0原文

以前,我通过放置 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦醒灬来后我 2024-12-09 17:44:04

BaseColumns._ID 添加到您的投影阵列。

Add BaseColumns._ID to your projection array.

败给现实 2024-12-09 17:44:04

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"

江湖正好 2024-12-09 17:44:04

查看您的查询。您可能会错误地写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..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文