gpt4 book ai didi

java - 尝试使用cursor.getCount(),无法解析符号getCount()

转载 作者:行者123 更新时间:2023-12-01 09:55:04 26 4
gpt4 key购买 nike

当我尝试使用cursor.getCount()时,我正在制作一个android项目;它给了我错误:

cannot resolve symbol getCount();

这是我的代码

class GetNotesFromDbTask extends AsyncTask<Void, Void, Boolean> {

@Override
protected Boolean doInBackground(Void... params) {
return null;
}

@Override
protected void onPreExecute() {
ProgressDialog dialog = new ProgressDialog(NoteDetail.this);
dialog.setTitle("Loading");
dialog.setMessage("Please wait..");
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setCancelable(false);
dialog.show();
}


SQLiteDatabase db = helpers.getReadableDatabase();
String[] projection = {
NoteContract.FeedEntry._ID,
NoteContract.FeedEntry.NOTES_TITLE,
NoteContract.FeedEntry.NOTES_ID,
NoteContract.FeedEntry.NOTES_BODY,

};

String sortOrder =
NoteContract.FeedEntry.NOTES_ID + " DESC";

Cursor cursor = db.query(
NoteContract.FeedEntry.TABLE_NAME, // The table to query
projection, // The columns to return
null, // The columns for the WHERE clause
null, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
);


if(cursor.getCount()>0) //here i am getting error

{

}

我也定义了光标,我不明白为什么它不起作用。

另外,

我尝试了if(cursor !=null)

它在对我说

cursor unknown class

最佳答案

您的代码应该位于类内部的方法内,而不是在类级别本身。

前面的行在语法上是有效的,因为它们是变量声明和初始化。 if 条件在类级别无效。

关于java - 尝试使用cursor.getCount(),无法解析符号getCount(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37302006/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com