测试add,返回报空指针
</pre></p><p><b>root cause</b> <pre>java.lang.NullPointerException com.mmall.service.impl.CartServiceImpl.getCartVoLimit(CartServiceImpl.java:161) com.mmall.service.impl.CartServiceImpl.list(CartServiceImpl.java:83) com.mmall.service.impl.CartServiceImpl.add(CartServiceImpl.java:57) com.mmall.controller.portal.CartController.add(CartController.java:43) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
找到CartServiceImpl.java 161行
cartTotalPrice = BigDecimalUtil.add(cartTotalPrice.doubleValue(),cartProductVo.getProductTotalPrice().doubleValue());
是这个东东,和老师的源码比对,没发现不同,最后直接重新copy一份老师的cartserviceimpl过来,报错依旧
tomcat日志如下
[08:27:10.260][DEBUG][c.m.dao.CartMapper.selectCartByUserId][http-bio-8088-exec-4] ==> Parameters: 1(Integer)
[08:27:10.261][DEBUG][c.m.dao.CartMapper.selectCartByUserId][http-bio-8088-exec-4] <== Total: 2
[08:27:10.262][DEBUG][org.mybatis.spring.SqlSessionUtils][http-bio-8088-exec-4] Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5c1649cf]
[08:27:10.276][DEBUG][org.mybatis.spring.SqlSessionUtils][http-bio-8088-exec-4] Creating a new SqlSession
[08:27:10.276][DEBUG][org.mybatis.spring.SqlSessionUtils][http-bio-8088-exec-4] SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@29c5322b] was not registered for synchronization because synchronization is not active
[08:27:10.278][DEBUG][o.m.s.t.SpringManagedTransaction][http-bio-8088-exec-4] JDBC Connection [jdbc:mysql://192.168.0.168:3306/mmall_learning?characterEncoding=utf-8, UserName=mmall@192.168.0.9, MySQL-AB JDBC Driver] will not be managed by Spring
[08:27:10.279][DEBUG][c.m.dao.ProductMapper.selectByPrimaryKey][http-bio-8088-exec-4] ==> Preparing: select id, category_id, name, subtitle, main_image, sub_images, detail, price, stock, status, create_time, update_time from mmall_product where id = ?
[08:27:10.279][DEBUG][c.m.dao.ProductMapper.selectByPrimaryKey][http-bio-8088-exec-4] ==> Parameters: 1(Integer)
[08:27:10.280][DEBUG][c.m.dao.ProductMapper.selectByPrimaryKey][http-bio-8088-exec-4] <== Total: 0
[08:27:10.281][DEBUG][org.mybatis.spring.SqlSessionUtils][http-bio-8088-exec-4] Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@29c5322b]
数据库里的数据是原始数据,也就是说在add时,是要新增cart的,一路调用,到这个核心方法时就报空指针了。
百思不得其解,请老师帮忙看看?