So basically, I have written this class to define a hashmap, with a method to access the values.
This is pretty explanatory, it is used as an answer key for a larger "quiz" program.
Whenever I try and run this, I get a "NullPointerException".
The parameter I am giving is an int (that SHOULD correspond with the key in the hashmap no?)
Any idea what is going wrong here?
package jQuiz; import java.util.*; import java.util.Collections; import java.util.HashMap; import java.util.Map; public class QuizAnswers { //create our map private static final Map<Integer,Character> mp = DefineAnswers(); private static Map<Integer, Character> DefineAnswers(){ Map<Integer, Character> question = new HashMap<Integer, Character>(); // Create our answer key question.put(0,'B'); question.put(1,'D'); question.put(2,'C'); question.put(3,'A'); question.put(4,'A'); question.put(5,'B'); question.put(6,'D'); question.put(7,'B'); question.put(8,'C'); question.put(9,'A'); return Collections.unmodifiableMap(mp); } public static char getAnswer(int QuestionNum) { //return our result return mp.get(QuestionNum); } }