java吧 关注:1,229,640贴子:12,689,640
  • 0回复贴,共1
@Override
public Student findStudentByExamId(String examId) {
Student s = null;
try {
Document doc = Tool.getDocument();
//先找到节点,在用节点进行判断
Node node = doc.selectSingleNode("//student[@examid='"+examId+"']");
if(node!=null){
Element e = (Element)node;
s = new Student();
s.setIdCard(e.valueOf("@idcard"));
s.setExamId(e.valueOf("@examid"));
s.setName(e.elementText("name"));
//上面一句等价:s.setName(e.element("name").getText());
s.setLocation(e.elementText("location"));
//单精度有静态方法 parseFloat 把文本转为 float.
s.setGrade(Float.parseFloat(e.elementText("grade")));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return s;
}
求助,哪个大神告诉下我这个方法用Junit测试时老报空指针错误到底出错在哪??


IP属地:陕西1楼2016-10-19 20:54回复