0
     <table border="1" style="width:300px">
     <tr><c:out value = "Ques. 1 ${question.question}"/></tr>
     <%
       @SuppressWarnings("unchecked")
       List<answers> ans = (List<answers>)request.getAttribute("question.answer");
       for(int i=0; i<ans.size();i++){  // LINE 14
       out.println(ans.get(i));
       }
     %>

This is jsp code!! I am new to JSP's. "question" is an attribute which i passed in jsp from my controller. Also , "answer" is variable defined in my question class.

This is throwing a null point exception on for-loop at line 14 . Although my answer variable which is of (List answer) type has values

Thanks for help

user2985842
  • 437
  • 9
  • 24

2 Answers2

0

Please use JSTL in your JSP.

It seems your ans is null so can you verify value of question.answer while setting in request from controller

you can refer to below link to avoid scriptlet in jsp

How to avoid Java code in JSP files?

Community
  • 1
  • 1
Gautam
  • 3,276
  • 4
  • 31
  • 53
0

Looks like your getParameter name is wrong. Your objects name is not "question.answer". you have:

List<answers> ans = (List<answers>)request.getAttribute("question.answer");

probably should be something like:

List<Answers> ans = ((Question)request.getAttribute("question")).answer;
ChrisThompson
  • 1,998
  • 12
  • 17