0
I am developing an online questionnaire in JSP, where the user selects the radio of each question to be validated. Example: a questionnaire of 25 questions, if the user reaches 25 and clicks the previous 24 and gives the next one to 25, generates the error java.lang.IndexOutOfBoundsException: Index: 25, Size: 25
. I was searching the Internet and found that this error may occur if a method tries to access a memory address in an array that does not exist, and has already reached its limit.
Class stretch Exam.class
that the system accuses the error:
Configuration Works, however, from the error, if the user comes back on the last questions of the exam and click on the later
for(int i=0;i<taken-1;i++){
System.out.println("i ExamController: "+i+ "taken: "+taken);
//o erro ocorre aqui!!!!
if((userSelectionsList.get(i)-1)==correctAnswersList.get(i)){
totalCorrect++;
System.out.println("totalCorrect ExamController: "+totalCorrect);
}
}
Code snippet that calls the compute method: /The exam will be finished when the user finishes or when the time limit for the exam is long./
else if("Finish Exam".equals(action)||( minute==0 && second==0))
{ finish=true;
/*Submetendo o Exame e Avaliação Resultado Exame. Quando o usuário clica no botão Concluir, ExamController
*chama o método calculateResult () passando o objeto Exame, calculateResult ()*/
int result=exam.calculateResult(exam,exam.questionList.size());
request.setAttribute("result",result);
request.getRequestDispatcher("/jsps/result.jsp").forward(request,response);
}
Console error:
Question number 0 recovered Question number 1 recovered Number Question 2 recovered Question number 3 recovered Question number 4 recovered Question number 5 recovered Question number 6 recovered Question number 7 recovered Question number 8 recovered Number question 9 recovered Question number 10 recovered Question number 11 recovered Question number 12 recovered Question number 13 recovered Question number 14 recovered Question number 15 recovered Question number 16 recovered Question number 17 recovered Question number 18 recovered Question number 19 recovered Question number 20 recovered Question number 21 recovered Question number 22 recovered Question number 23 recovered Question number 24 recovered You clicked Previous Button Question number 23 recovered Question number 24 recovered You clicked Previous Button Question number 23 recovered You clicked Button Previous Question number 22 recovered Question number 23 recovered Question number 24 recovered
i Examcontroller: 0taken: 32 totalCorrect Examcontroller: 1 i Examcontroller: 1taken: 32 i Examcontroller: 2taken: 32 i Examcontroller: 3taken: 32 i Examcontroller: 4taken: 32 i Examcontroller: 5taken: 32 i Examcontroller: 6taken: 32 i Examcontroller: 7taken: 32 i Examcontroller: 8taken: 32 i Examcontroller: 9taken: 32 i Examcontroller: 10taken: 32 i Examcontroller: 11taken: 32 totalCorrect Examcontroller: 2 i Examcontroller: 12taken: 32 totalCorrect Examcontroller: 3 i Examcontroller: 13taken: 32 i Examcontroller: 14taken: 32 i Examcontroller: 15taken: 32 i Examcontroller: 16taken: 32 i Examcontroller: 17taken: 32 i Examcontroller: 18taken: 32 i Examcontroller: 19taken: 32 i Examcontroller: 20taken: 32
Jun 17, 2016 5:52:48 PM org.apache.Catalina.core.Standardwrappervalve invoke GRAVE: Servlet.service() for Servlet [br.com.tkcsapcd.quiz.controller.Examcontroller] in context with path [/Tkcsapcd_cadastros] threw Exception java.lang.Indexoutofboundsexception: Index: 25, Size: 25 at java.util.Arraylist.rangeCheck(Unknown Source) at java.util.Arraylist.get(Unknown Source) at br.com.tkcsapcd.quizz.Exam.calculateResult(Exam.java:128) at br.com.tkcsapcd.quiz.controller.ExamController.doPost(Examcontroller.java:127) at javax.servlet.http.HttpServlet.service(Httpservlet.java:646) at javax.servlet.http.HttpServlet.service(Httpservlet.java:727) at org.apache.Applicationfilterchain.internalDoFilter(Applicationfilterchain.java:303) at org.apache.Catalina.core.Applicationfilterchain.doFilter(Applicationfilterchain.java:208) at org.apache.Tomcat.websocket.server.WsFilter.doFilter(Wsfilter.java:52) at org.apache.Applicationfilterchain.internalDoFilter(Applicationfilterchain.java:241) at org.apache.Catalina.core.Applicationfilterchain.doFilter(Applicationfilterchain.java:208) at org.apache.Catalina.core.Standardwrappervalve.invoke(Standardwrappervalve.java:220) at org.apache.Catalina.core.Standardcontextvalve.invoke(Standardcontextvalve.java:122) at org.apache.Catalina.authenticator.Authenticatorbase.invoke(Authenticatorbase.java:501) at org.apache.Catalina.core.Standardhostvalve.invoke(Standardhostvalve.java:170) at org.apache.Catalina.valves.Errorreportvalve.invoke(Errorreportvalve.java:98) at org.apache.Catalina.valves.Accesslogvalve.invoke(Accesslogvalve.java:950) at org.apache.Catalina.core.Standardenginevalve.invoke(Standardenginevalve.java:116) at org.apache.Catalina.connector.Coyoteadapter.service(Coyoteadapter.java:408) at org.apache.Coyote.http11.Abstracthttp11processor.process(Abstracthttp11processor.java:1040) at org.apache.Coyote.Abstractprotocol$Abstractconnectionhandler.process(Abstractprotocol.java:607) at org.apache.Tomcat.util.net.Jioendpoint$Socketprocessor.run(Jioendpoint.java:315) at java.util.Concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.Concurrent.Threadpoolexecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
How could I fix this?