I'm trying to make a very basic software simulation of a router that reads in a text file and acts on the commands and other information given to it. I made a new class called groupclass to hold an ArrayList
package router;
import java.util.ArrayList;
public class groupclass
{
public ArrayList<String> member;
}
Made a HashMap with it as the value
static Map<Integer, groupclass> groupmap = new HashMap<Integer, groupclass>();
And tried this code
private static void groupadd(int groupnum, String address)
{
out.println("debug groupadd");
try
{
groupmap.get(groupnum).member.add(address);
}
catch(NullPointerException e)
{
groupmap.put(groupnum, new groupclass());
groupmap.get(groupnum).member.add(address);
}
}
Which throws a NullPointerException at
groupmap.get(groupnum).member.add(address);
The idea was to make a map and associate a new groupclass object with each group number, and each groupclass would have a list of IPs stored as strings. I'm at a complete loss here, and any tweaks I do cause weirder problems and build errors I don't understand.
Thanks in advance!