在数据获取查询时在数据库类中的错误

我想通过 rowId 和 subjectId 从表格中获取数据,但是获取错误:

The method query(boolean, String, String[], String, String[], String, String, String, String) in the type SQLiteDatabase is not applicable for the arguments 
(boolean, String, String[], String, String, null, null, null, null)

执行查询的代码:

public Cursor getText(long rowId, long subId) throws SQLException 
{
Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {
        KEY_id, KEY_ques,KEY_correctans,KEY_wrongans1,KEY_wrongans2,KEY_wrongans3,KEY_subject,KEY_subjectid }, KEY_id + "="
        + rowId, KEY_subjectid + "=" + subId,null,null, null,null);
if (mCursor != null) 
{
    mCursor.moveToFirst();
}
return mCursor;
}

我想在条件 subId = KEY_subjectid 和 rowId = KEY_id 下获取表格数据。

请问错误是怎么出现的呢?

该回答引用ChatGPT

根据错误提示信息:

The method query(boolean, String, String[], String, String[], String, String, String, String) in the type SQLiteDatabase is not applicable for the arguments (boolean, String, String[], String, String, null, null, null, null)

可以看出,方法 query() 中的参数传递有误,特别是第五个参数,该参数用于指定条件语句的值,但是在你的代码中,该参数被设置为 null。由于你想要查询的是两个条件 subId = KEY_subjectid 和 rowId = KEY_id 下的数据,因此你需要传递一个包含这两个条件的查询语句,例如:

String selection = KEY_id + "=? AND " + KEY_subjectid + "=?";
String[] selectionArgs = new String[] { String.valueOf(rowId), String.valueOf(subId) };
Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {
    KEY_id, KEY_ques, KEY_correctans, KEY_wrongans1, KEY_wrongans2, KEY_wrongans3, KEY_subject, KEY_subjectid },
    selection, selectionArgs, null, null, null, null);

这样,你就可以通过 rowId 和 subjectId 从表格中获取数据了。