gpt4 book ai didi

java - Android:从ArrayList中提取数据

转载 作者:行者123 更新时间:2023-12-01 11:24:22 25 4
gpt4 key购买 nike

我想从 ArrayList 中提取数据,但 LogCat 显示空值。

我的代码是:

try {
String sql = "SELECT Cname FROM demo";
Statement stmt = con.createStatement();
final ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
arrData.add(rs.getString("Cname").toString());
}
Campaign campaign_data[] = new Campaign[] {
new Campaign(R.drawable.empty, "Today:"+ arrData.indexOf(0)),
new Campaign(R.drawable.empty, "This Month:" + arrData.indexOf(1))
};
} catch() {
}

最佳答案

arrData 是 ArrayList 类型吗?

您似乎正在对其调用indexOf(0),这可能不是您想要的。

public int indexOf(Object o)

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.

我假设您打算调用 get(i),因此请尝试以下操作:

      new Campaign(R.drawable.empty, "Today:"+ arrData.get(0)),
new Campaign(R.drawable.empty, "This Month:" + arrData.get(1))

关于java - Android:从ArrayList中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30954875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com