2016-10-05 46 views
0

Android開發者。我有一個SQLite數據庫。我的一列被稱爲KEY_SWITCH。我想將這個列表中的整數轉換成ArrayList,然後將其打印到我的控制檯。爲什麼我無法打印從我的SQLite表生成的我的ArrayList?

這裏是我的代碼:

public ArrayList<Integer> getAllIntegerValues() { 
    ArrayList<Integer> yourIntegerValues = new ArrayList<Integer>(); 
    Cursor result = db.query(true, DATABASE_TABLE, 
      new String[] {KEY_SWITCH}, null, null, null, null, 
      null, null); 

    if (result.moveToFirst()) { 
     do { 
      yourIntegerValues.add(result.getInt(result 
        .getColumnIndex(KEY_SWITCH))); 
     } while (result.moveToNext()); 
    } else { 
     return null; 
    } 
    System.out.print(yourIntegerValues); 
    return yourIntegerValues; 
} 

我像這樣運行

DBAdapter_Metrics mydbmetric; 

private SQLiteDatabase dbmetric; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_metric_list); 
    openDBMetrics(); 
    populateListViewFromDNewBMetric(); 
    mydbmetric.getAllIntegerValues(); 
} 

代碼當我運行代碼,我收到以下錯誤: endAllActiveAnimators on 0x915c1380 (RippleDrawable) with handle 0x8f550150

爲什麼不它打印我的ArrayList?

我試圖尋找這個錯誤,但我發現不同的地方在我的代碼啓動getAllIntegerValues()

例如錯誤的變化,當我創建了一個下拉菜單中的選項來運行它,我得到了這個錯誤

endAllActiveAnimators on 0x8e3b5300 (MenuPopupWindow$MenuDropDownListView) with handle 0x8ef83f50

因此,似乎取決於在那裏我運行它,我不明白轉移。

回答

0

做象下面這樣:

System.out.print(Arrays.toString(yourIntegerValues.toArray())); 

UPDATE:一種方法是象下面這樣:

System.out.print(android.text.TextUtils.join(",", yourIntegerValues)) 
+0

工程。但是,我現在有一個單獨的問題。它只打印一個值,這是因爲該列中的每個條目都爲零。我如何獲得ArrayList的所有值?也就是說,我希望它打印[0 0 0 ..... 0] –

+0

使用print而不是println並查看它是否可用 –

+0

我更新了答案。 –

相關問題