I am Developing Movie Rental Application in JSP. After selecting movie with the help of checkbox, when I am iterating with that it is giving me null pointer exception. Here is the code for Statement.jsp file which is creating statement for the rented movies...
<%@page language="java" %>
<%@page import="java.sql.*, java.util.*, mrs.*" %>
<html>
<head>
<title>Movie Rental Application</title>
</head>
<body>
<%@include file="Connection.jsp" %>
<% if (session.getAttribute("Name") != null) {
String[] checkboxes = null;
String[] days = null;
checkboxes = request.getParameterValues("c1");
days = request.getParameterValues("t1");
int i = 0;
for (String title : checkboxes) {
String Name = session.getAttribute("Name").toString();
int code = 0;
ResultSet rs = stmt.executeQuery("select Type from Movies where Title = '" + title + "'");
String Type = rs.toString();
if (Type.equalsIgnoreCase("REGULAR")) {
code = 0;
}
if (Type.equalsIgnoreCase("NEW RELEASE")) {
code = 1;
}
if (Type.equalsIgnoreCase("CHILDREN")) {
code = 2;
}
mrs.Movie m = new mrs.Movie(title, code);
int day = Integer.parseInt(days[i]);
i++;
mrs.Rental r = new mrs.Rental(m, day);
mrs.Customer c = new mrs.Customer(Name);
c.addRental(r);
stmt.executeQuery("insert into rents values('" + day + "','" + Name + "','" + title + "')");
String result = c.statement();
out.println(result);
}
stmt.close();
con.close();
%>
<% }%>
</body>
</html>
Here it is the Exception...