【发布时间】:2014-09-09 15:09:56
【问题描述】:
public int countContacts() {
String query = "select count(name) from contacts";
int count = db1.execSQL(query); // I got error at this line
return count;
}
我试图通过使用上面的代码来计算表中的行数。但是我收到了这个错误-“类型不匹配:无法从 void 转换为 int”。为什么会出现此错误,我该如何纠正?
更新:
db1 是 SQLiteDatabase。
我使用 Eclipse 进行编码。我在编码时遇到了这个错误。我什至没有运行代码。
【问题讨论】:
-
db1 有什么类型?你读过 JavaDoc 吗?
-
什么是 db1?你能粘贴完整的代码吗?如果它是preparedStatement,则需要调用executeUpdate 而不是executeQuery
-
@talex 你所说的 db1 类型是什么意思?
-
可以添加错误详情吗?
-
@Manu Jacob 每个变量都有一个与之关联的类型。您在声明变量时指定它。