内部阵列列表<;Hashmap>;添加android后,是否在末尾显示null?

内部阵列列表<;Hashmap>;添加android后,是否在末尾显示null?,android,arraylist,hashmap,Android,Arraylist,Hashmap,我正在访问数据库中的数据并存储在arraylist中,但在最后显示完整列表时,它显示null 输出: 09-01 17:26:49.550:E/数据(16620):--->15 09-01 17:26:49.550:>E/data(16620):--->[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[, []、[]、[]、[]、[]、[]、[]、[]、[]、[]] publicstaticarraylisttestdata(SQLiteD

我正在访问数据库中的数据并存储在arraylist中,但在最后显示完整列表时,它显示null

输出:

09-01 17:26:49.550:E/数据(16620):--->15

09-01 17:26:49.550:>E/data(16620):--->[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[…]、[, []、[]、[]、[]、[]、[]、[]、[]、[]、[]]

publicstaticarraylisttestdata(SQLiteDatabase db)
{
整数计数=0;
int k=0;
阵列列表数据=
新的ArrayList();
奥达塔酒店=
新的ArrayList();
字符串查询=
“从myfiles中选择*”+
“其中((日期时间('2014-09-01 09:50:15')>=开始日期”+
日期时间('2014-09-01 09:50:15')=strftime('%H:%M:%S',计时器\u从)+
“和'09:50:15'+data.size());
Log.e(“数据”、“--->”+数据);
cursor.close();
返回数据;
}

您已成功地将哈希映射添加到列表中。计数也显示为15。唯一的问题是,您无法在哈希映射上正确存储或正确显示

当您向映射、列表或集合添加元素时,会添加原始对象,而不会创建副本,因此,如果您修改它,它将被删除在集合中修改。简单示例:

class Foo {
  public int bar;
}
在另一段代码中使用该简单类

List<Foo> myList= new ArrayList<>();

Foo f= new Foo(); //we create a Foo object, and f is a variable that references it
f.bar=9; 
myList.add(f);  //we add the object to the list
然后

将在屏幕上显示
15

在代码中,您正在重用同一对象。请创建一个新对象,而不是调用
clear()

odata = new ArrayList<HashMap<String,String>>();
odata=newarraylist();

总之:您可以重用变量,但在这种情况下,您不能重用引用的对象。

但是我在添加之后清除了arraylist,而不是为什么它会影响我的主列表“主列表”是什么意思?arraylist data=new arraylist();是否为主列表您确定有正确的查询?是否确定cursor.getCount()选中此处我显示完整的播放列表谢谢对我有用odata=new ArrayList();您好需要更多帮助吗
f.bar=15;
System.out.println(myList.get(0))
odata = new ArrayList<HashMap<String,String>>();