My project is e learning project. I've a "choose the correct answer" module. When the click the "begin test" button it should fetch the questions and options from database and display it. Instead of that my page displays "java.lang.NullPointerException".
I've assigned unique values for each error. So the exact error it display as
"error occured 56 : java.lang.NullPointerException"
I have found the area of the error. but i couldn't solve it.
My codings are as follows
<html>
<%@ page import="INCLUDES.DBConnection"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="DB" scope="page" class="INCLUDES.DBConnection"/>
<jsp:setProperty name="DB" property="*"/>
<jsp:useBean id="DB1" scope="page" class="INCLUDES.DBConnection"/>
<jsp:setProperty name="DB1" property="*"/>
<jsp:useBean id="DB2" scope="page" class="INCLUDES.DBConnection"/>
<jsp:setProperty name="DB2" property="*"/>
<%
String dbase=(String)session.getAttribute("dbase");
String trainee_id=(String)session.getAttribute("trainee_id");
String user_name=(String)session.getAttribute("user_name");
if(user_name==null)
{
response.sendRedirect("course_list_index2.jsp");
}
int attempt_id=Integer.parseInt((String)session.getAttribute("attempt_id"));
int number_of_questions=Integer.parseInt((String)session.getAttribute("number_of_questions"));
int course_id=Integer.parseInt((String)session.getAttribute("course_id"));
int paper_id=Integer.parseInt((String)session.getAttribute("paper_id"));
String statement=null;
ResultSet objRs=null;
ResultSet objRsQNo=null;
ResultSet objRsQ=null;
int no_of_papers=0,paper_no=0;
String course_name="",trainee_name="",paper_name="";
try
{
statement="select * from x_master_elearning_user u,x_master_trainee_detail_online t,x_masterListOfCourses c ,x_masterListOfPapers p where p.course_id=c.course_id and c.course_id=t.course_id and t.user_name=u.user_name and c.course_id=" + course_id + " and u.user_name='" + user_name + "' and p.paper_id=" + paper_id;
DB.setStatement(statement);
objRs=(ResultSet)DB.result();
if(objRs.next())
{
course_name=objRs.getString("course_name");
trainee_name=objRs.getString("first_name");
paper_name=objRs.getString("paper_name");
no_of_papers=objRs.getInt("no_of_papers");
paper_no=objRs.getInt("paper_no");
}
}
catch(Exception e)
{
out.print("error occured 1 :" + e);
}
int i=0;
if(request.getParameter("question_no")==null)
{
i=1;
}
else
{
i=Integer.parseInt(request.getParameter("question_no"))+1;
}
try
{
statement="select * from results where paper_id=" + paper_id + " and course_id=" + course_id + " and trainee_id='" + trainee_id + "'";
DB1.setStatement(statement);
objRsQNo=(ResultSet)DB1.result();
if(objRsQNo.next())
{
if(i<= number_of_questions)
{
statement="select * from x_masterListOfQuestions where paper_id=" + paper_id + " and question_id=" + objRsQNo.getInt("qn" + i);
DB2.setStatement(statement);
objRsQ=(ResultSet)DB2.result();
}
}
}
catch(Exception e)
{
out.print("error occured 22 :" + e);
}
%>
<head>
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<LINK rel="stylesheet" type="text/css" href="mystyle.css">
<TITLE>Help and Support</TITLE>
<SCRIPT language="JavaScript" src="ajaxfiles/ajaxfunction.js"></SCRIPT>
</HEAD>
<BODY class="backgrounpicture" style="margin:0px">
<script src="topmenu.js"></script>
<form method="post" action="exam_question_insert.jsp" >
<input type="hidden" name="question_no" value=<%=i%>>
<table width="75%" align="right" >
<tr>
<td colspan="3"><hr color="#FFFFff" noshade size="1"></td>
</tr>
<%
try
{
if(objRsQ.next())
{
%>
<tr >
<td width="9%" class="infoLabel">Q No.<strong><%=i%></strong></td>
<td colspan="2" class="infoValue"><%=objRsQ.getString("question")%></td>
</tr>
<tr>
<td> </td>
<td colspan="2" class="infoValue"> <input type="radio" name="choice<%=i%>" value=1>
<%=objRsQ.getString("choice1")%></td>
</tr>
<tr>
<td> </td>
<td colspan="2" class="infoValue"> <input type="radio" name="choice<%=i%>" value=2>
<%=objRsQ.getString("choice2")%></td>
</tr>
<tr>
<td> </td>
<td colspan="2" class="infoValue"> <input type="radio" name="choice<%=i%>" value=3>
<%=objRsQ.getString("choice3")%></td>
</tr>
<tr>
<td> </td>
<td colspan="2" class="infoValue"> <input type="radio" name="choice<%=i%>" value=4>
<%=objRsQ.getString("choice4")%></td>
</tr>
<%
}
}
catch(Exception e)
{
out.print("error occured 56 : " + e);
}
%>
<tr>
<td colspan="3"><hr color="#FFFFff" noshade size="1"></td>
</tr>
<tr>
<td align=center> </td>
<td align="right">
<%if(i== number_of_questions)
{
%>
<div align="right">
<input type="submit" value="Finish" style="font-size:13pt;" name="submit" onClick="return fnConfirm()">
<%
}
else
{
%>
<input type="submit" value="Next" style="font-size:13pt;" name="submit">
<%
}
%>
</div></td>
<td width="47%" align="right"><input type="submit" value="Review" style="font-size:13pt" name="submit"></td>
</tr>
</table>
</form>
</body>
</html>
Please help me to solve this error. i'll be very thankful to you. If you need extra code tell me which part you want to solve this error. I'll post here. thanks to everyone. A little piece of help also appriciated