从 ArrayList> 取值

问题描述:

我在从 ArrayList> 获取值时遇到问题.

I have a problem about getting a value from my ArrayList<HashMap<String, String>>.

我的代码是:

ArrayList<HashMap<String, String>> myArrayList;

然后:

HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID, id);
map.put(TAG_NAME, name);
myArrayList.add(map);

例如,如果我想获取名称,我尝试了以下操作,但出现运行时错误(应用程序崩溃):

If I want to get the name, for example, I tried as follow but I obtain a runtime error (the application crashes):

System.out.println(myArrayList.get(1).get(TAG_NAME));

我该如何解决?

非常感谢!

System.out.println(myArrayList.get(1).get(TAG_NAME));

ArrayList 从 0 开始.get(0) 代替.

ArrayList is 0-based. get(0) instead.