测试购物车那一节报错
来源:2-15 nginx反向代理服务器安装与配置讲解(选看)

章小熊熊
2017-05-30
测试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的,一路调用,到这个核心方法时就报空指针了。
百思不得其解,请老师帮忙看看?
7回答
-
012017-05-30
-
章小熊熊
提问者
2017-05-30
弄了一天了,始终找不到问题,最后发现数据库里cart表有一条userid=1,productid=1的可疑记录,也不晓得是听视频如何操作加上去的,反正我没直接写sql操作数据库。
把这一条删掉,报错解决。
汗。。。
142020-02-14 -
章小熊熊
提问者
2017-05-30
注释掉
// if(cartItem.getChecked() == Const.Cart.CHECKED){
// //如果已经勾选,增加到整个的购物车总价中
// cartTotalPrice = BigDecimalUtil.add(cartTotalPrice.doubleValue(),cartProductVo.getProductTotalPrice().doubleValue());
// }然后就不报错了,只是逻辑少了totalprice。
奇怪,这里为什么会报错?
112019-05-27 -
章小熊熊
提问者
2017-05-30
后面继续step out ,还跳转到了如图的地方终止
00 -
章小熊熊
提问者
2017-05-30
设置了断点,step out一路执行,对象都是有值的。
然后在
cartTotalPrice = BigDecimalUtil.add(cartTotalPrice.doubleValue(),cartProductVo.getProductTotalPrice().doubleValue());
这个断点再step out就跳转到public class InvocableHandlerMethod extends HandlerMethod这个方法的
private Object invoke(Object... args) throws Exception 方法了,如下图所示。
00 -
章小熊熊
提问者
2017-05-30
初次编程,debug是指以debug模式启动tomcat吗?要设置断点吗?
还有,怎么查看每个对象的值?
不好意思,请指教啊。
00 -
Geely
2017-05-30
hi 同学多余NPE其实是最容易解决的,可以debug一下,到那一行,挨个对象看一下,看看是哪个为空,我想这个是一个解决问题的思路。
00
相似问题