2016-07-28 164 views
1

我使用這個代碼,但它返回空值。當我調試我的代碼,顯示其給出的空值列表返回空值

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: ==>[email protected] 
E/0_0: 0_0 1=> 
E/Hey: last 

幫我出這一點。

+0

爲什麼你需要檢查'cursor.isLast()'? –

+0

在'while'中放置一個'Log',看看'cursor'是否返回數據。 – Venky

+0

看我的日誌venky – newdeveloper

回答

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); 
+0

很多很多的感謝其現在的工作 – newdeveloper

+0

(可能是空的,雖然)最後一個問題,如果你是自由 – newdeveloper

+0

@newdeveloper如果您有其他問題,請在另一篇文章,然後給我一個鏈接。快樂編碼 –