我知道这是一个菜鸟问题,但我无法在网上找到任何东西。我有这个 HashMap :
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) children.item(i);
map.put("title", ParseXMLmethods.getValue(e, "title"));
map.put("pubDate", ParseXMLmethods.getValue(e, "pubDate"));
map.put("link", ParseXMLmethods.getValue(e, "link"));
map.put("description",ParseXMLmethods.getValue(e, "description"));
localist.add(map);
我收到有关本地化的错误消息:“无法解析本地化”。我知道我必须声明本地化但我不知道要使用哪种变量类型。非常感谢任何帮助。
最佳答案
首先,将您的 Map 变量声明为接口(interface) Map 并将它们初始化为实现,例如
Map<String, String> map = new HashMap<String, String>();
您还可以使用菱形运算符 <> 来推断模板类型,例如
HashMap<String, String> map = new HashMap<>();
虽然以上内容不是必需的,但它们是很好的做法。 现在,要声明本地化,您可以执行以下操作:
List<Map<String, String>> localist = new ArrayList<>();
这是将字符串映射到字符串的映射列表。
关于java - android: HashMap 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19039101/