这个错误如何解决呢
2012-05-18 11:15:59,185 [com.database.DataBaseOperator]-[ERROR] java.lang.NullPointerException
java.lang.NullPointerException
at com.database.DataBaseOperator.queryList(DataBaseOperator.java:40)
at com.developer_order.OrderService.getOrderEmerge(OrderService.java:54)
at org.apache.jsp.order.developers_005forder_jsp._jspService(developers_005forder_jsp.java:69)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
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:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
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)
2012-05-18 11:15:59,186 [com.database.DataBaseOperator]-[INFO] select a.order_id,to_char(a.createtime,'yyyy-MM-dd') createtime,a.user_grade,b.goodsname,b.shopping_number,b.unitprice,b.totalprice,(case b.issend when 1 then '已经发货'when 0 then '暂未发货'end) issend,b.trade_price,b.trade_total from orderr a, order_info b where 1 = 1 and a.order_id = b.order_id /n共查询0条记录!
2012-05-18 11:15:59,186 [com.lb.nt.clientAPI.Operator.JsonUtil]-[INFO] 正在进行List转换成JSON操作...............
2012-05-18 11:15:59,186 [com.lb.nt.clientAPI.Operator.JsonUtil]-[INFO] 将List转换成JSON操作完成!
package com.database;
import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.SQLException;import java.util.List;
import org.apache.log4j.Logger;
import com.common.CommonFunc;import com.util.StringUtil;
public class BatchDataBaseOperator { private static final Logger log = Logger.getLogger(DataBaseOperator.class); @SuppressWarnings("unchecked") public static boolean insertbatchDataForPhoto(String sql,List list){ log.info("插入图片......"); boolean b = false; Connection conn = CommonFunc.getConnection(); PreparedStatement st = null; try { st = conn.prepareStatement(sql); st.setInt(1, 1); st.executeUpdate(sql); st.close(); b = true; } catch (SQLException e) { // TODO Auto-generated catch block //e.printStackTrace(); log.error(e,e); } finally{ if(conn!=null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block //e.printStackTrace(); log.error(e,e); } } } return b; } public static boolean updatebatchDataForaddress(String default_address_id,String now_default_address_id){ log.info("更改默认邮箱......"); boolean b = false; Connection conn = CommonFunc.getConnection(); PreparedStatement st = null; try { st = conn.prepareStatement("update send_address t set t.status=? where 1=1 and t.send_address_id=?"); st.setInt(1, 0); st.setInt(2, StringUtil.stringToInt(default_address_id)); st.addBatch(); st.setInt(1, 1); st.setInt(2, StringUtil.stringToInt(now_default_address_id)); st.addBatch(); st.executeBatch(); st.close(); b = true; } catch (SQLException e) { // TODO Auto-generated catch block //e.printStackTrace(); log.error(e,e); } finally{ if(conn!=null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block //e.printStackTrace(); log.error(e,e); } } } return b; }
}
--------------------编程问答-------------------- 先检查下你的数据库连接是否成功
2,看下OrderService第54行
3,设置断点调试下 --------------------编程问答-------------------- 你首先把为空的对象找出来。
然后,去看看为什么为空。问题也就解决了。 --------------------编程问答-------------------- com.developer_order.OrderService.getOrderEmerge(OrderService.java:54)
里面肯定有一个方式是根据穿来的值进行查询 或者插入什么的?
肯定有一个参数获取的时候是空的 导致类型转换的时候由于空值 无法转换而产生的空指针异常
只要找出是哪个值为空就可以。
建议后台输出所有获取的值 --------------------编程问答-------------------- java.lang.NullPointerException
at com.database.DataBaseOperator.queryList(DataBaseOperator.java:40)
at com.developer_order.OrderService.getOrderEmerge(OrderService.java:54)
OrderService.java:54,最好对对象先判断是否为 null 在操作
--------------------编程问答-------------------- public static JSONArray getOrderEmerge(HttpServletRequest request ){
JSONArray jsonArray = null;
String developer_id = OperateSession.getSession(request, "developer_id").toString(); //获得商家ID;
String developer_type = OperateSession.getSession(request, "developer_type").toString(); //用户类型
String order_id = StringUtil.getRequestString(request, "order_id"); //订单的编号
String goodsname = StringUtil.getRequestString(request, "goodsname"); //商品名称
String startime = StringUtil.getRequestString(request, "startime"); //开始时间
String endtime = StringUtil.getRequestString(request, "endtime"); //结束时间
StringBuffer sql = new StringBuffer ("select a.order_id,to_char(a.createtime,'yyyy-MM-dd') createtime,a.user_grade,b.goodsname,b.shopping_number,b.unitprice,b.totalprice,(case b.issend when 1 then '已经发货'when 0 then '暂未发货'end) issend,b.trade_price,b.trade_total from orderr a, order_info b where 1 = 1 and a.order_id = b.order_id " );
//条件查询开始 and b.developer_id = '"+developer_id+"'
if(order_id!="") { //判断订单编号是否为空
sql.append (" and a.order_id="+order_id+""); //执行SQL语句将订单编号为条件
}
if(goodsname!=""){ //判断商品名称是否为空
sql.append(" and goodsname='"+goodsname+"'"); //执行SQL语句将商品名称为条件
}
if(startime!=""||endtime!=""){ //判断起始时间与结束时间是否为空
sql.append(" and a.createtime between to_date('"+startime+"','yyyy-MM-dd') and to_date('"+endtime+"','yyyy-MM-dd')");
} //执行查询时间区间
List<DynaBean> list = DataBaseOperator.queryList(sql.toString());
jsonArray = JsonUtil.listDynaBeanToJson(list);
//日志开始
String[] operate = new String [7];
operate[0] = developer_id; //用户ID
if(developer_type.equals("0")){
operate[1] = SystenLogBean.usertype_3; //用户类型,根据具体业务(开发者)
}
else operate[1] = SystenLogBean.usertype_2;
operate[2] =SystenLogBean.system_2; //系统模块id,根据具体业务
operate[3] = SystenLogBean.action_6; //操作类型,根据具体业务
operate[4] = SystenLogBean.object_5; //操作对象,根据具体业务
operate[5] = SystenLogBean.reslut_0; //操作结果,根据具体业务
operate[6] = request.getRemoteAddr(); //ip地址,根据具体业务
if(!jsonArray.equals("")){
operate[5] = SystenLogBean.reslut_1;
SystemLog.insertLog(CommonParam.LOGIN_LOG_TEMPLATE, CommonParam.SYS_MODULE_LOGIN, operate);
}else{
SystemLog.insertLog(CommonParam.LOGIN_LOG_TEMPLATE, CommonParam.SYS_MODULE_LOGIN, operate);
}
return jsonArray;
}
}
补充:Java , Web 开发