以下结果是我的 HashMap
值,我通过循环条款填充该值
private Map<String, String> days = new HashMap<>();
0 = {HashMap$HashMapEntry@4952} "2131689719" -> "2016-11-25"
1 = {HashMap$HashMapEntry@4953} "2131689683" -> "2016-11-26"
2 = {HashMap$HashMapEntry@4954} "2131689692" -> "2016-11-27"
3 = {HashMap$HashMapEntry@4955} "2131689686" -> "2016-11-26"
4 = {HashMap$HashMapEntry@4956} "2131689716" -> "2016-12-01"
现在,当我尝试搜索一个给定键的值时,例如:
days.get("2131689719")
我得到null
更新:
int day = 0;
int dateOfWeeks = 10;
for (int i = 0; i <= 6; i++) {
((TextView) findViewById(food_list_values[i])).setText(dayOfWeeks[day]);
days.put(String.valueOf((findViewById(food_list_values[i])).getId()), foodList.get(dateOfWeeks).getDate());
day++;
dateOfWeeks++;
}
我想您可以将值添加为String
,并尝试将其作为Integer
获取,这可能会导致此问题。请尝试以下
days.get(Integer.toString(findViewById(food_list_values[i])).getId()));
我怀疑地图天只有一个元素 null, <last date>
这是不正确的
findViewById(food_list_values[i]))
FindViewById通常使用您在Android应用程序中定义的R.ID资源,