将值从活动传递到数据源的问题

时间:2012-12-21 09:00:45

标签: android sqlite android-cursoradapter

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

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敬酒它会返回正确的值。

1 个答案:

答案 0 :(得分: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);