为什么我无法打印从我的SQLite表生成的ArrayList?

时间:2016-10-05 04:55:53

标签: android sqlite arraylist

Android开发者。我有一个SQLite数据库。我的一个列名为KEY_SWITCH。我想将此列表中的整数转换为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

所以它似乎取决于我运行它的位置,我不明白。

1 个答案:

答案 0 :(得分:0)

如下所示:

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

更新:另一种方式如下:

System.out.print(android.text.TextUtils.join(",", yourIntegerValues))
相关问题