我无法弄清楚为什么会收到此错误。我检查并重新检查了我的代码似乎没有发现任何错误。
16 Jul, 2012 3:21:25 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [XYZ] in context with path [/ABC] threw exception
java.lang.NullPointerException
at com.mnp.abc.xyz.doPost(XYZ.java:116)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
XYZ servlet 的 doPost 方法
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
StringBuilder sb = new StringBuilder();
InputStream rin = request.getInputStream();
InputStream gzipStream = new GZIPInputStream(rin);
Reader decoder = new InputStreamReader(gzipStream, "UTF-8");
BufferedReader br = new BufferedReader(decoder);
String str;
// retrieve JOSNArray send to Servlet
while ((str = br.readLine()) != null) {
sb.append(str);
}
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(sb.toString());
} catch (JSONException e) {
System.out.println("Error parsing JSON");
}
System.out.println("json object: " + jsonArray.toString());
// parse JSONArray and obtain ContactArray
ArrayList<Contact> contactArray = null;
try {
contactArray = frmJSONArrayToContactArray(jsonArray);
} catch (JSONException e1) {
System.out.println(TAG + " frmJSONArrayToContactArray Failed");
}
// connect JDBC with MySQL server
Context initContext;
Connection connection;
DataSource datasource;
Statement statement;
ResultSet rs = null;
try {
initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
datasource = (DataSource) envContext.lookup("jdbc/bolsms");
// load Connector/J
connection = datasource.getConnection();
statement = connection.createStatement();
// get query String
Iterator<Contact> itetor = contactArray.iterator();
boolean greatPeopleBoo = false;
while (itetor.hasNext()) {
***Contact contact = itetor.next();***
....
....
....
}
rs.close();
statement.close();
connection.close();
} catch (NamingException ex) {
Logger.getLogger(MarkGreatPeopleFromContact.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException e) {
for (Throwable t : e) {
System.out.println(t.getMessage());
}
}
/*
* send contactArray back to Android Client
*/
}
}