0

我收到了这个错误:

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

和负责的代码:

public Cursor getDomanda(String id) {
            List<categorie> categorie = new ArrayList<categorie>();

            Cursor cursor = database.query(MySQLiteHelper.TABLE_SONDAGGI,
                allCategorieColumns, MySQLiteHelper.COLUMN_ID + "=", id, null, null, null);

            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
              categorie categoria = cursorToCategorie(cursor);
              categorie.add(categoria);
              cursor.moveToNext();
            }
            // Make sure to close the cursor
           // cursor.close();
            return cursor;
          }

另一方面:

long strcategory = getIntent().getExtras().getLong("categoriaId"); 
Cursor values = datasource.getDomanda(Long.toString(strcategory));

我做错了什么?我需要将 long 转换为,String[]但到底是什么String[]?:D 顺便说一句......查询对吗?我的意思是

database.query(MySQLiteHelper.TABLE_SONDAGGI,
                    allCategorieColumns, MySQLiteHelper.COLUMN_ID + "=", id, null, null, null);

select from tableSondaggi where _id = $id ?
4

2 回答 2

2

第 4 个参数必须是 a String[],而不是 a String

您需要替换idbynew String[] { id }以创建一个由一个元素(您的 id)组成的数组。

  Cursor cursor = database.query(MySQLiteHelper.TABLE_SONDAGGI,
            allCategorieColumns, MySQLiteHelper.COLUMN_ID + "=", new String[] { id }, null, null, null);
于 2012-12-20T16:14:24.187 回答
1

这应该可以解决问题。

Cursor cursor = database.query(MySQLiteHelper.TABLE_SONDAGGI,
            allCategorieColumns, MySQLiteHelper.COLUMN_ID + "=",  new String[] { id }, null, null, null);

但是:也许有必要阅读一些有关基本编程的书籍。数组(String[]例如)非常有用......

于 2012-12-20T16:15:27.920 回答