【问题标题】:Why am I unable to print my ArrayList generated from my SQLite table?为什么我无法打印从我的 SQLite 表生成的 ArrayList?
【发布时间】:2016-10-05 04:55:53
【问题描述】:

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

所以它似乎会根据我运行它的位置而发生变化,我不明白。

【问题讨论】:

    标签: android sqlite arraylist


    【解决方案1】:

    如下所示:

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

    更新:另一种方式如下:

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

    【讨论】:

    • 那行得通。但是,我现在有一个单独的问题。它只打印一个值,0。这是因为列中的每个条目都是零。如何将 ArrayList 获取到所有值?也就是说,我希望它打印 [0 0 0 ..... 0]
    • 没有 println,你只会得到原始错误。第二段代码也产生了原始错误。
    • 第一个作品正在我的设备上运行。无论您的所有数据是否为 ​​0。即使您的条目为空,第一个也有效!
    • 您的错误不是因为列表。动画师和动画有问题。你在你的项目中使用过它们吗?
    • 尝试捕获并打印堆栈跟踪错误。把错误告诉我,我会告诉你的。
    猜你喜欢
    • 1970-01-01
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多