I have the following code:
String table;
private DB.ConnectMAS mas=new DB.ConnectMAS();
java.sql.ResultSet rs1 = mas.DBquery("select * from products");
try{
String duedate = "";
while(rs1.next()){
String duedate = rs1.getString("duedate");
table+="<tr><td>"+duedate.substring(1,10)+"</td></tr>";
} catch(java.sql.SQLException e){}
It is throwing an error on duedate.substring(1,10)
I’m trying to understand why this is incorrect?
thanks in advance
error:
SEVERE: Servlet.service() for servlet POList threw exception
java.lang.NullPointerException
at POList.getDetails(POList.java:126)
at POList.getTable(POList.java:165)
at POList.processRequest(POList.java:55)
at POList.doGet(POList.java:177)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:834)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)
at java.lang.Thread.run(Unknown Source)
Like @danben says, you need to post the error to get meaningful help. Looking at your code, though, I’d imagine that
duedateat the time of the error isnull. You probably need to move the code that’s actually usingduedateinside yourwhileloop.