I have a hashmap that contains multiple string arrays. I am trying to output each element in one of the arrays of the hashmap however I seem to always get
java.lang.NullPointerException
Here is my code,
import java.util.HashMap;
public class TestApp {
private static HashMap<String, String[]> subjects;
public TestApp() {
HashMap<String, String[]> subjects = new HashMap<String, String[]>();
subjects.put("calculus",new String[] {"math","logic"});
subjects.put("chemisty",new String[] {"ions","electrons"});
subjects.put("biology",new String[] {"life","bacteria"});
}
public static void main(String[] args){
for(String s:subjects.get("biology")){
System.out.println(s);
}
}
}
How can i stop this issue?