当前位置: 代码迷 >> Java Web开发 >> NullPointerException帮小弟我找找异常,纠结死了
  详细解决方案

NullPointerException帮小弟我找找异常,纠结死了

热度:179   发布时间:2016-04-17 10:43:57.0
NullPointerException帮我找找错误,纠结死了
Java code
      public BasicInf getBasicInf(String staId){          BasicInf BasicInf=null;          try{              ps = connection.prepareStatement("select * from BasicInf where staId=?");              ps.setString(1,staId);              ResultSet rs = ps.executeQuery();              while (rs.next()) {                  System.out.println(rs.getString(1));                  System.out.println(rs.getString(2));                  System.out.println(rs.getString(3));                  System.out.println(rs.getString(4));                                    BasicInf.setStaId(rs.getString(1));                  BasicInf.setBirthday(rs.getString(2));                  BasicInf.setNation(rs.getString(4));                  BasicInf.setSex(rs.getString(3));                  return BasicInf;              }          }catch(Exception e)          {              e.printStackTrace();          }          return BasicInf;      }

System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getString(4));正确输出了数据库里的数据
可是到了BasicInf.setStaId(rs.getString(1));就直接catch了,也不知道错在哪里,求大神们帮帮忙看下,分不多笑纳

------解决方案--------------------
你又把BasicInf设置成null了
探讨

改成如下Java code
public BasicInf getBasicInf(String staId){
BasicInf BasicInf=new BasicInf();
try{
ps = connection.prepareStatement("select * from BasicInf where staId……
  相关解决方案