Android Q(SDK 29)上的“ContentResolver无效列错误”
创始人
2024-08-15 03:30:21
0

在Android Q(SDK 29)上,如果你在使用ContentResolver查询数据时遇到“无效列错误”(Invalid column error),这可能是因为该列不存在或者列名被更改了。

解决方法如下:

  1. 确保你查询的表中确实存在该列。你可以通过查看数据库模式或者表结构来确认。

  2. 如果列名被更改了,你需要更新你的查询语句中的列名。确保列名的大小写和拼写与表中的列名完全匹配。

下面是一个使用ContentResolver查询数据的示例代码:

String[] projection = {
    ContactsContract.Contacts._ID,
    ContactsContract.Contacts.DISPLAY_NAME
};

Uri uri = ContactsContract.Contacts.CONTENT_URI;

Cursor cursor = getContentResolver().query(uri, projection, null, null, null);

if (cursor != null && cursor.moveToFirst()) {
    int idColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts._ID);
    int nameColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);

    do {
        String contactId = cursor.getString(idColumnIndex);
        String contactName = cursor.getString(nameColumnIndex);

        // 处理查询结果
        Log.d(TAG, "Contact ID: " + contactId + ", Name: " + contactName);
    } while (cursor.moveToNext());
}

if (cursor != null) {
    cursor.close();
}

在这个示例中,我们查询了系统联系人的ID和显示名。你可以根据你的需求修改projection数组中的列名,并根据你的数据模型进行处理。

如果你仍然遇到“无效列错误”,请检查你的列名拼写和大小写,并确保列名在表中存在。

相关内容

热门资讯

揭幕透视!wepoker网页版... 揭幕透视!wepoker网页版透视方法,微乐自建房辅助可信吗,技法教程(有挂助手)-哔哩哔哩一、we...
解密透视!来玩app破解版,微... 解密透视!来玩app破解版,微乐小程序怎么挂脚本,绝活儿教程(有挂方法)-哔哩哔哩1、来玩app破解...
总结透视!cloudpoker... 总结透视!cloudpoker作弊,微信小程序微乐房间怎么辅助,教程书教程(有挂详情)-哔哩哔哩cl...
推荐透视!aa poker辅助... 推荐透视!aa poker辅助,微信小程序 微乐陕西挖坑 外挂,阶段教程(有挂详细)-哔哩哔哩1、玩...
详细透视!poker worl... 详细透视!poker world辅助器,微乐自建房怎么提高胜率,技法教程(有挂教学)-哔哩哔哩1、实...
详情透视!如何下载wepoke... 详情透视!如何下载wepoker安装包,手机微乐小程序破解器,教程书教程(有挂猫腻)-哔哩哔哩详情透...
科普透视!werplan怎么作... 科普透视!werplan怎么作弊,微信小程序微乐破解填大坑,指引教程(确实有挂)-哔哩哔哩所有人都在...
了解透视!wepoker免费脚... 了解透视!wepoker免费脚本咨询,微乐小程序怎么挂脚本,诀窍教程(有挂分享)-哔哩哔哩了解透视!...
普及透视!哈糖大菠萝助手,微乐... 普及透视!哈糖大菠萝助手,微乐自建房辅助工具,指引教程(确实有挂)-哔哩哔哩一、哈糖大菠萝助手游戏安...
了解透视!wepokerplu... 了解透视!wepokerplus万能挂,微乐自建房辅助工具2025在哪,积累教程(存在有挂)-哔哩哔...