列表返回null值

时间:2016-07-28 09:45:20

标签: android database sqlite

我正在使用此代码,但它返回null值。当我调试我的代码,显示其给定的空值

 List<TextJson> textList = null;
    try{
        textList = new ArrayList<TextJson>();
         Cursor cursor = db.rawQuery("SELECT * FROM "+TABLE_TEXTS + " WHERE " + KEY_CATE + " = '" + text_spinner1 + " ' " , null);
          Log.e("Cursor is","==>"+cursor);
            Log.e("0_0", "0_0   1=>"); // code working on here
         if(!cursor.isLast())
           {
            Log.e("Hey","last");
            while (cursor.moveToNext())
            {
                TextJson txtlist = new TextJson();
                txtlist.setId(cursor.getInt(0));
                txtlist.setText_status(cursor.getString(1));
                textList.add(txtlist);
            }
        }
        db.close();
    }catch (Exception e){
        Log.e("error","is==> "  +e);
    }
    return textList; // null value

我的日志

E/Spinner value is: --=> speech
E/inside: getDetailtospinner
E/Cursor is: ==>android.database.sqlite.SQLiteCursor@41b0f5d8
E/0_0: 0_0   1=>
E/Hey: last

帮助我解决这个问题。

1 个答案:

答案 0 :(得分:1)

更改

Cursor cursor = db.rawQuery("SELECT * FROM "+TABLE_TEXTS + " WHERE " + KEY_CATE + " = '" + text_spinner1 + " ' " , null);

Cursor cursor = db.rawQuery("SELECT * FROM "+TABLE_TEXTS + " WHERE " + KEY_CATE + " = '" + text_spinner1 + "'" , null);
// or Cursor cursor = db.rawQuery("SELECT * FROM "+TABLE_TEXTS + " WHERE " + KEY_CATE + " LIKE '" + text_spinner1 + "'" , null);