问题描述
java.lang.NullPointerExceptionaction.ImgAction.regImg(ImgAction.java:27)sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)java.lang.reflect.Method.invoke(Method.java:597)com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)我的action是packageaction;importmodel.Img;importimpl.impldao;publicclassImgAction{privateimpldaodaoiz;privateImgimg=newImg();publicImgAction(){super();}publicImgAction(Imgimg){super();this.img=img;}publicImggetImg(){returnimg;}publicvoidsetImg(Imgimg){this.img=img;}publicStringregImg(){booleanboo=daoiz.imgReg(img);System.out.println(img.getImgname());System.out.println(img.getImgtype());if(boo){return"OK";}else{return"NO";}}}
解决方案
解决方案二:
daoiz这个东西初始化了吗?
解决方案三:
名字起得太不规范了。。。publicStringregImg(){booleanboo=daoiz.imgReg(img);System.out.println(img.getImgname());System.out.println(img.getImgtype());if(boo){return"OK";}else{return"NO";}}
img是新创建的对象,你没有对它进行赋值,是空的对吧,接口的实现调用空的对象得到boolean。你就把boolean打印出来呀。教你,以后出现看见偶那个指针就用System.out()查查。。。
解决方案四:
楼主的daoiz是依赖注入的么?查一查配置文件,是否并未注入
解决方案五:
daoiz这对象怎么来的