Android 获取 Arraylist的问题从光标开始

发布于 2024-10-05 19:05:57 字数 673 浏览 3 评论 0原文

我需要从光标获取一个值。该值需要采用这种格式:

        List<double[]> values = new ArrayList<double[]>();

问题是当我执行“.add”时,它会错误地要求我将其更改为“length”。我必须将它放在列表中才能使应用程序正常工作。这是我的代码,有办法做到这一点吗?我做错了什么?

    cursor = managedQuery(Provider.CONTENT_URI,
            proj,
            null,
            null,
            null);

            while (cursor.moveToNext()) { 
        double value; 
        column_value = cursor.getColumnIndex(CsvProvider.VALUE);
        value = cursor.getDouble(column_value);
        values.add(value); //this did not work
        values.add(new double[] {value}); //this did work
    } ;

谢谢迈克!

I need to get a value from my cursor. The value needs to be in this format:

        List<double[]> values = new ArrayList<double[]>();

The problem is when I do the ".add" it errors wanting me to change it to "length". I have to have it in the List for the app to work at all. Here is my code, is there a way to do that? What am I doing wrong?

    cursor = managedQuery(Provider.CONTENT_URI,
            proj,
            null,
            null,
            null);

            while (cursor.moveToNext()) { 
        double value; 
        column_value = cursor.getColumnIndex(CsvProvider.VALUE);
        value = cursor.getDouble(column_value);
        values.add(value); //this did not work
        values.add(new double[] {value}); //this did work
    } ;

Thanks Mike!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷情 2024-10-12 19:05:57

首先,你永远不应该解释错误。如果出现错误,请将其复制并粘贴到您的问题中。

至于您的问题:

您有一个双数组列表,即 cValues 列表中的每个条目都需要是 double[]。然而,您只是添加一个普通的双精度值。那是行不通的。我不知道你的列表应该如何设置,如果你错误地将 [] 放入或者你确实需要一个数组列表,但假设每个条目都需要一个双精度数组,那么你需要添加new double[] { value }

旁注:为什么不简单地 while (cursor.moveToNext()) { ... } 而不是这个 do/while 结构呢?

First of all, you should never paraphrase errors. If you get an error, copy and paste it into your question.

As to your problem:

You have a list of double arrays, i.e. every single entry in your cValues List needs to be a double[]. Instead, however, you're just adding a plain double. That won't work. I don't know how your list is supposed to be setup, if you put the [] in by mistake or if you really need a list of arrays, but assuming that every entry needs an array of one double, then you need to add a new double[] { value }.

Side note: Why not simply while (cursor.moveToNext()) { ... } instead of this do/while construct?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文