Trying to add init parameter names to a list in init(ServletConfig) method.
public void init(ServletConfig sc){
try {
super.init(sc);
Enumeration<String> e= sc.getInitParameterNames();
while(e.hasMoreElements()){
list.add(e.nextElement());
}
} catch (ServletException e1) {
e1.printStackTrace();
}
}
I am getting a NullPointerException when I use this list because e.hasMoreElement() returns false. I am pretty sure that I have added the init parameters correctly in the web.xml file. What is going wrong? Please advice.
list
is null.list
has not bee initialized (see Ramesh's answer below) - and not because you didn't add elements to it. BTW: How shall we tell if you used the init parameters correctly if you don't post the code where you set them?