Struts2问题 action要用的model对象 需要实例化吗
Struts2问题 action要用的model对象 需要实例化吗
我用的struts2+hibernate3.0+spring2.0架构
下面是代码片段:
public class ArrangedutyAction extends BaseAction {
/**
*
*/
private static final long serialVersionUID = 1L;
private ArrangedutyManager arrangedutyManager;
private List list;
private CompanyManager companyManager;
private Arrangeduty arrangeduty;
private int c_id;
我用到Arrangeduty 的model对象是这样写会报错
java.lang.NullPointerException
at com.anrui.aroa.web.actions.sp.ArrangedutyAction.add(ArrangedutyAction.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation
如果改成就不会出错了啊
public class ArrangedutyAction extends BaseAction {
/**
*
*/
private static final long serialVersionUID = 1L;
private ArrangedutyManager arrangedutyManager;
private List list;
private CompanyManager companyManager;
private Arrangeduty arrangeduty=new Arrangeduty();
private int c_id;
但是我同事他们都用第一种方法 也没错误 有些资料也不用new Arrangeduty() 为什么到我这就错了 希望高手解答我的疑问
[解决办法]