A line in my program which declares a Hashmap triggers an error.
public class SubjectTeacherPeriod{
private int id;
private Map<String, Integer> num_attribute_map;
private Map<String,List<String>> str_attribute_map;
private Period period;
private List<Period> periodList;
public SubjectTeacherPeriod(){
num_attribute_map = new HashMap<String, Integer>();
str_attribute_map = new HashMap<String,List<String>>(); //THIS LINE
}
....
is responsible for:
jesvin@Jesvin-Technovia:~/dev/drools/timetabler$ java -server in.co.technovia.timetabler.TimeTableApp
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.HashMap.<init>(HashMap.java:226)
at in.co.technovia.timetabler.domain.SubjectTeacherPeriod.<init>(SubjectTeacherPeriod.java:38)
at in.co.technovia.timetabler.solution.TimeTableInitializer.createTimeTable(TimeTableInitializer.java:66)
at in.co.technovia.timetabler.TimeTableApp.main(TimeTableApp.java:37)
What is wrong with my hashmap?
Update: just like all answers guessed, a bad loop variable created too many variables. It was not a problem of the hashmap itself.
Nothing is wrong with your hash map. (How could it be? You’re just declaring it / instantiating it.)
My guess would be that you’re creating an enormous number of
SubjectTeacherPeriodobjects which basically fills the memory with hash maps. In the end it doesn’t have room for one more.