日期:2014-05-20 浏览次数:20810 次
public static List<ReceivedBean> getReceived(){ List<ReceivedBean> beans = null; ReceivedBean bean = null; Connection conn = null; PreparedStatement pst = null; ResultSet rs = null; try { conn = DBPoolConn.getConn(); String sql = "select * from db_customsms.dbo.tbl_smreceived"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { bean.setSm_id(rs.getInt("SM_ID")); bean.setOrgaddr(rs.getString("orgaddr")); bean.setDestaddr(rs.getString("destaddr")); bean.setSm_content(rs.getString("sm_content")); bean.setRecvtime(rs.getString("recvtime")); bean.setReserve1(rs.getInt("reserve1")); bean.setReserve2(rs.getString("reserve2")); bean.setSmtype(rs.getInt("smtype")); bean.setMessageid(rs.getString("messageid")); bean.setOrgaddrtype(rs.getInt("orgaddrtype")); bean.setActionid(rs.getInt("actionid")); bean.setActionreasonid(rs.getInt("actionreasonid")); bean.setServiceid(rs.getString("serviceid")); bean.setProtocoltype(rs.getString("protocoltype")); bean.setReaded(rs.getInt("readed")); bean.setDroped(rs.getInt("droped")); beans.add(bean); System.out.println(bean.getSm_id()); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ DBPoolConn.CloseAll(rs, pst, conn); } return beans; }
Exception in thread "main" java.lang.NullPointerException at com.chinagdn.services.SendMessage.getReceived(SendMessage.java:28) at com.chinagdn.services.SendMessage.main(SendMessage.java:82)
while (rs.next()) { bean = new ReceivedBean(); //还没new,当然是null了 bean.setSm_id(rs.getInt("SM_ID"));
------解决方案--------------------
bean 是空的。
bean = new ReceivedBean();
------解决方案--------------------
ReceivedBean bean = null; 没初始化…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………