I am making project on online examination in java. I am facing a problem.
On starting base I have 15 questions in my database and I am fetching those sequentially.
The problem is that if I attempt all the answers I get the results otherwise I get error 500 and NullPointerException. The questions are multiple choice. Every question has four options. If I don't attempt all the questions then I get the above error.
<%@page import="java.sql.*"%>
<%
    String st[] = new String[20];
    String ans[] = new String[20];
    int k=0;
    //int length = Integer.parseInt(request.getAttribute("length").toString());
    for (int i = 0; i < 15; i++)
    {
        int j = i + 1;
        st[i] = request.getParameter("radio" + j);
        System.out.println(st[i]);
    }
    Class.forName("oracle.jdbc.OracleDriver");
    Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "root", "root");
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery("Select ANS from ANSWERS order by ID");
    //String ans = "";
    int t;
    while (rs.next()) {
        ans[k] = rs.getString("ans");
        k++;
        System.out.println(ans[k]);
    }
    int count = 0;
    //String answers[] = ans.split(" ");
    for (int i = 0; i < 15; i++) {
        if (st[i].equals(ans[i])) {
            count++;
        }
    }
    out.println("Your " + count + " answers are correct");
%>
 
     
     
     
    