求助,开发一论坛,打开一网页出现一个
空指针异常,自己找了很久没找出问题,求帮助
这是错误信息:
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /article.jsp at line 7
4: <%!
5: private void tree(List<Article> articles, Connection conn, int id, int grade) {
6: String sql = "select * from article where pid = " + id;
7: Statement stmt = DB.createStmt(conn);
8: ResultSet rs = DB.executeQuery(stmt, sql);
9: try {
10: while(rs.next()) {
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handle
JspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
com.bjsxt.bbs.DB.createStmt(DB.java:27)
org.apache.jsp.article_jsp.tree(article_jsp.java:16)
org.apache.jsp.article_jsp._jspService(article_jsp.java:88)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.
------解决方案--------------------感觉应该是你的conn没有执行 conn = DriverManager.getConnection(URL,userName,userPwd);
你把这句放到26行的try中吧;