2012-10-13 79 views
0
Cursor cur = acc.query("details", new String[] { "name"}, null, 
      null, null, null, null); 

    cur.moveToFirst(); 
    listContent = new String[cur.getCount()]; 
    for (i = 0; i < cur.getCount(); i++) { 
     String ss1; 
     ss1 = cur.getString(0); 
     listContent[i] = ss1; 

     cur.moveToNext(); 
    } 
    cur.close(); 
+1

更細,更好地解釋你想要做什麼 – Yaroslav

+0

什麼是與此代碼有關的s_no?什麼是與這個代碼有關的名字。對「詳細信息」的查詢不爲我們所知,所以您需要更好地定義字段或我們無法幫助您。 –

+1

@ user1742971檢查演示..... http://stackoverflow.com/questions/12338131/exception-while-retriving-data-from-the-sqlitedatabase/12853460#12853460 –

回答

0

嘗試爲:

Cursor cur = acc.query("details", new String[] { "name"}, null, 
     null, null, null, null); 
listContent = new String[cur.getCount()]; 
int i=0; 
while(cur.moveToNext()) { 
    listContent[i] =cur.getString(0); 
    i++; 
} 
cur.close(); 

和簡單的方法做同樣沒有使用,而不是陣列中的任何索引計數器使用ArrayList爲:

Cursor cur = acc.query("details", new String[] { "name"}, null, 
     null, null, null, null); 
List<String> strArrayList = new ArrayList<String>(); 

while(cur.moveToNext()) { 
    strArrayList.add(cur.getString(0)); 
} 
cur.close();