Android SQLite查询: "queryNumEntries .. is not applicable for the arguments"?

标签 android sqlite

我有一个名为 contacts.db 的数据库,其中有一个名为 TABLE_NAME 的表,其中有一列名为 Contactname。我想格式化一个查询来检查作为字符串变量名称中的值的联系人姓名是否已保存为表中的记录,如果不是,则我想添加它,否则什么都不做。我写的代码如下:

SQLiteDatabase db = events.getReadableDatabase();
int rawNum = DatabaseUtils.queryNumEntries(db, TABLE_NAME, 
                        "Contactname=?", new String[] {contactName}); 
    if(rawNum==0){
        addRecord(contactName);
        addedCounter+=1;
    }
    else{
        savedCounter+=1;
    }

但应用程序被迫关闭。你能看出查询有什么问题吗?我所做的是查看是否有行,如果行数为 0,则添加联系人。

最佳答案

也许是时候更新您的开发套件了。

代码中使用的带有签名的方法是在 API 级别 11 中引入的:

public static long queryNumEntries (SQLiteDatabase db, String table, String selection, String[] selectionArgs)

API Level 1 只有两个参数的方法:

public static long queryNumEntries (SQLiteDatabase db, String table)

关于Android SQLite查询: "queryNumEntries .. is not applicable for the arguments"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11213195/

相关文章:

创建连接时出现 SQLite 异常

sql - 选择给定时间间隔的行

java - Cloud Firestore 中的值在求和运算期间重复

java - 媒体 Controller 不工作

android - 工作管理器 : Cannot access database on the main thread since it may potentially lock the UI for a long period of time

用于存储常量的 Android 嵌套接口(interface)

android - 如何以编程方式从启动器中删除 Activity ?

java - Android 数据库中的 ClassCastException

android SQLite 不遵守 "not null"约束

python - 两个进程能否访问内存中(:memory:) sqlite database concurrently?