【发布时间】:2013-07-12 02:16:23
【问题描述】:
Map<String, String> listOfIndexes = INDEXED_TABLES.get(tableName);
Iterator it = listOfIndexes.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
System.out.println(pairs.getKey());
}
我的Hashmap是这样的:
public static Map<String, Map<String, String>> INDEXED_TABLES = new HashMap<String, Map<String, String>>()
{{
put("employee", EMPLOYEE);
}};
public static Map<String, String> EMPLOYEE = new HashMap<String, String>()
{{
put("name", "Test");
put("age", "Test");
put("sex", "test");
}};
【问题讨论】:
-
异常的javadoc列出了所有可能的原因:docs.oracle.com/javase/7/docs/api/java/lang/…
-
谢谢...不过,你有我的数据和电话。我一直在尝试解决这个问题。
-
如果你使用一个不存在的“tablename”,你会在第二行得到一个 NPE。
-
大声笑......哦,是的,我应该有。
标签: java collections nullpointerexception iterator hashmap