2016-10-05 56 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

我更新了答案。 –

相关问题