1

尝试从数据库中获取文本后,出现此错误:

12-21 09:54:10.948: E/AndroidRuntime(25745): FATAL EXCEPTION: main
12-21 09:54:10.948: E/AndroidRuntime(25745): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ggservice.democracy/com.ggservice.democracy.sondaggioActivity}: android.database.sqlite.SQLiteException: near "=": syntax error: , while compiling: SELECT _id, preferita, nome FROM sondaggi WHERE _id=

这是电话:

Cursor values = datasource.getDomanda(strcategory );
        if (values.moveToFirst()) // data?
               System.out.println(values.getString(values.getColumnIndex("domanda"))); 

               values.close(); 

它称之为:

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

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

            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
              sondaggi sondaggio = cursorToSondaggi(cursor);
              domande.add(sondaggio);
              cursor.moveToNext();
            }

            return cursor;
          }

id 接缝是空的,但我知道那里有一个值,我已经测试了变量通道。我的意思是,如果我敬酒 strcategory 它返回正确的值。

4

1 回答 1

1

改变

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

  Cursor cursor = database.query(MySQLiteHelper.TABLE_SONDAGGI,
                    allCategorieColumns,
                    MySQLiteHelper.COLUMN_ID + "=?",
                    new String[] { id }, null, null, null);
于 2012-12-21T09:05:11.337 回答