public class AgentInfoAction extends DispatchAction {
/*
 * Generated Methods
 */
AgentInfoManager agMager; public AgentInfoManager getAgMager() {
return agMager;
} public void setAgMager(AgentInfoManager agMager) {
this.agMager = agMager;
} /**
 * Method execute
 * 
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
AgentInfoForm agf = (AgentInfoForm) form;
String id = request.getParameter("id");
TAgentinfo aginfo = null;
if(id==null){
id="";
}
if (id.equals("0")) {
id = "";
}
if (id.equals("")) {
aginfo = new TAgentinfo();
aginfo.setId(2000);
} else {
aginfo = agMager.getSingData(id);
}
aginfo.setAddrs(agf.getAddrs());
aginfo.setAgentname(agf.getAgentname());
aginfo.setCityname(agf.getCityname());
aginfo.setTel(agf.getTel());

agMager.add(aginfo);在这个地方总是报NullPointerException 其实aginfo这个对象中是有值的。
return list(mapping, form, request, response);
} public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List<TAgentinfo> aginfolist = agMager.getAllData();
request.setAttribute("aginfolist", aginfolist);
return mapping.findForward("aglist");
} public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String id = request.getParameter("id");
agMager.delete(id);
return list(mapping, form, request, response);
} public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
AgentInfoForm agf = (AgentInfoForm) form;// TODO
String id = request.getParameter("id");
TAgentinfo aginfo  = agMager.getSingData(id);
agf.setAddrs(aginfo.getAddrs());
agf.setAgentname(aginfo.getAgentname());
agf.setCityname(aginfo.getCityname());
agf.setTel(aginfo.getTel());
agf.setId(aginfo.getId());
return  new ActionForward("/form/ageInfo_add.jsp");
}
}

解决方案 »

  1.   

    AgentInfoManager agMager=new AgentInfoManager() 试试
    这个错误一般是由于什么没有实例化
      

  2.   

    AgentInfoManager agMager 注入没有成功,试一下System.out.println(agMager==null);
      

  3.   

    aginfo.setAddrs(agf.getAddrs());
    aginfo.setAgentname(agf.getAgentname());
    aginfo.setCityname(agf.getCityname());
    aginfo.setTel(agf.getTel());
    把这几个的值都打印一片看一些,有没有值
      

  4.   

    agMager这个没有成功注入,你查下struts和spring整合的配置吧
      

  5.   

    aginfo 对象是有值的, 可能是#5楼所说的没有注入成功
    谢谢大家的指点
      

  6.   

    agMager.add(aginfo);抛NullPointerException跟aginfo没有关系,应该是agMager对象为null,也就是大家说的agMager这个没有成功注入。这样调用add方法时就会抛NullPointerException异常。
      

  7.   

    要么是在你注入的时候出问题了,所以获取的对象是Null!检查下是否注入成功!
      

  8.   

    引用一个null没错,错的是你用这个null去做了某些操作