显示空指针异常
来源:6-2 店铺信息编辑之Service层的实现
慕桂英1047953
2020-04-08
这是错误信息
at com.imooc.o2o.service.impl.ShopServiceImpl.modifyShop(ShopServiceImpl.java:72)
at com.imooc.o2o.service.ShopServiceTest.testModifyShop(ShopServiceTest.java:32)
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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
这是shopserviceimpl72行附近的代码
public ShopExecution modifyShop(Shop shop, InputStream shopImgInputSream, String filename) throws ShopOperationException {
if(shop==null || shop.getShopId()==null && filename !=null && !"".equals(filename)){
return new ShopExecution((ShopStateEnum.NULL_SHOP));
}else {
//判断是否需要创建目录
if(shopImgInputSream!=null){
Shop tempShop=shopDao.queryByShopId(shop.getShopId( ));
第72行的代码:if(tempShop.getShopImg()!=null){
ImageUtil.deleteFileOrPath(tempShop.getShopImg());
}
addShopImg(shop,shopImgInputSream,filename);
}
写回答
3回答
-
慕桂英1047953
提问者
2020-04-09
if(tempShop.getShopImg()!=null){
这就是第72行代码
012020-04-10 -
翔仔
2020-04-09
同学好,这里最好可以截图,我不知道你的第72行是哪里呀。。而且你的这错误信息也没截全,如果是
Shop tempShop=shopDao.queryByShopId(shop.getShopId());
则主要看看shopDao这个成员变量有没有加上@Autowired标签,如果加了,看看shopDao.xml里面是否配置正确 ,主要看看和package相关的事情
012020-04-09 -
慕桂英1047953
提问者
2020-04-08
这一行提示我可能会造成空指针异常
Shop tempShop=shopDao.queryByShopId(shop.getShopId());
00
相似问题