[英]How to resolve NoSuchElement: null in Java Sap Hybris?
I create an action that modified a value into one or more items (Order), order in status "wait for manual export" into "export", now when i selected the Orders and click on action button nothing change and into the log i have this error:我创建了一个将值修改为一个或多个项目(订单)的操作,订单状态为“等待手动导出”到“导出”,现在当我选择订单并单击操作按钮时,没有任何变化并进入我的日志这个错误:
ERROR [hybrisHTTP33] [ManualOrderExportAction]
ERROR: java.util.NoSuchElementException: null
at java.util.Collections$EmptyIterator.next(Collections.java:4210) ~[?:?]
at myExtension.backoffice.actions.ManualOrderExportListAction.perform(ManualOrderExportListAction.java:37) [?:?]
Code:代码:
@Resource(name = "businessProcessService")
private BusinessProcessService businessProcessService;
@Override
public ActionResult<Object> perform(ActionContext<Object> actionContext){
HashSet<OrderModel> hashSet = (HashSet<OrderModel>) actionContext.getData();
try
{
businessProcessService.triggerEvent(hashSet.iterator().next().getOrderProcess().iterator().next().getCode() + "_" + "SaitManualExportEvent" ); //line 37 that generate error.
Messagebox.show(POPUP_MESSAGE);
return new ActionResult<>(ActionResult.SUCCESS);
}
catch (final Exception ex)
{
LOG.error("ERROR: ", ex);
return new ActionResult<>(ActionResult.ERROR);
}
}
The below lines:以下几行:
...
businessProcessService.triggerEvent(hashSet.iterator().next().getOrderProcess().iterator().next().getCode() + "_" + "SaitManualExportEvent" ); //line 37 that generate error.
Messagebox.show(POPUP_MESSAGE);
return new ActionResult<>(ActionResult.SUCCESS);
...
should be changed to, something like:应更改为,例如:
...
if (hashSet.iterator().hasNext())
{
// NOTE: Don't know the data type returned by getOrderProcess(), so
// assumed a dummy data type OrderProcess
OrderProcess o = hashSet.iterator().next().getOrderProcess();
if (o.iterator().hasNext())
{
businessProcessService.triggerEvent(o.iterator().next().getCode() + "_" + "SaitManualExportEvent" );
Messagebox.show(POPUP_MESSAGE);
return new ActionResult<>(ActionResult.SUCCESS);
}
}
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.