[求助] action调用serivce,service调用dao报空指针异常!!!

sx513240563 2017-11-18 03:15:18
报错信息
2017-11-18 14:46:11,552 [http-nio-8080-exec-8] ERROR org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler - Exception occurred during processing request: null
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:542)
at java.lang.Integer.valueOf(Integer.java:766)
at cn.sx.action.PaymentAction.paymentadd(PaymentAction.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:870)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1293)
at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at java.lang.Thread.run(Thread.java:745)


action类:
public class PaymentAction extends ActionSupport{

private PaymentService paymentService;

public void setPaymentService(PaymentService paymentService) {
this.paymentService = paymentService;
}

private HttpServletRequest request = ServletActionContext.getRequest();

/**
* 缴费信息添加
*/
public String paymentadd(){
String proid = request.getParameter("property");
String type = request.getParameter("type");
String paycycle = request.getParameter("paycycle");
String cost = request.getParameter("cost");
String remark = request.getParameter("remark");

Property pro = paymentService.findprobean(Integer.valueOf(proid));


Payment pay = new Payment();

pay.setProperty(pro);
pay.setType(type);
pay.setPaycycle(paycycle);
pay.setCost(cost);
pay.setRemark(remark);
pay.setPaymentlock(0);
pay.setCreatetime(new Date());
pay.setPaytime(new Date());

paymentService.insertpayment(pay);

return "repaymentlist";
}


service类:
@Transactional
public class PaymentService {

private PaymentDao paymentDao;

public void setPaymentDao(PaymentDao paymentDao) {
this.paymentDao = paymentDao;
}
public Property findprobean(Integer proid) {
return paymentDao.findprobean(proid);
}


dao类:
public interface PaymentDao {

Property findprobean(Integer proid);}


dao实现类:
public class PaymentDaoImpl extends HibernateDaoSupport implements PaymentDao {
public void insertpayment(Payment pay) {
this.getHibernateTemplate().save(pay);
}

public Property findprobean(Integer proid) {
List<Property> list = (List<Property>) this.getHibernateTemplate().find("from Property where proid = ?", proid);
if (list!=null && list.size()!=0) {
return list.get(0);
}
return null;
}


spring:
<bean id="paymentAction" class="cn.sx.action.PaymentAction" scope="prototype">
<property name="paymentService" ref="paymentService"></property>
</bean>

<bean id="paymentService" class="cn.sx.service.PaymentService" scope="prototype">
<property name="paymentDao" ref="paymentDaoImpl"></property>
</bean>

<bean id="paymentDaoImpl" class="cn.sx.dao.PaymentDaoImpl" scope="prototype">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>



我用断点找了,结果是显示
求助大神!!
...全文
481 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
在dao的头上有@service 没有 或者错了都走不进去
墨笙弘一 2017-11-20
  • 打赏
  • 举报
回复
List<Property> list = (List<Property>) this.getHibernateTemplate().find("from Property where proid = ?", proid); if (list!=null && list.size()!=0) { return list.get(0); } return null; 看看你这个list是不是为null 如果为null 那么你返回的就是null 当然最后null不能转为数字就会报哪个错啊
墨笙弘一 2017-11-20
  • 打赏
  • 举报
回复
java.lang.NumberFormatException: null 看看你那个action 是不是有值
遥远的想念 2017-11-20
  • 打赏
  • 举报
回复
java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:542) at java.lang.Integer.valueOf(Integer.java:766) at cn.sx.action.PaymentAction.paymentadd(PaymentAction.java:86) 这里报错信息比较明显了,PaymentAction这个类的86行,前面报转化失败,那应该传了个错误的类型或者null过来了
dengdengdeng0908 2017-11-20
  • 打赏
  • 举报
回复
at cn.sx.action.PaymentAction.paymentadd(PaymentAction.java:86) 这行代码是啥
guan_tu 2017-11-20
  • 打赏
  • 举报
回复
应该是proid为null,报错的是Integer.valueOf()这个方法,不知道楼主是怎么调试出dao为null的
Sunyiban 2017-11-20
  • 打赏
  • 举报
回复
java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:542) 这该是参数问题吧
sx513240563 2017-11-18
  • 打赏
  • 举报
回复
断点显示的是paymentDao为空,proid是有值的
李德胜1995 2017-11-18
  • 打赏
  • 举报
回复
java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:542) at java.lang.Integer.valueOf(Integer.java:766) at cn.sx.action.PaymentAction.paymentadd(PaymentAction.java:86) PaymentAction的86行,打印proid是否为null???

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧