问题:
调用list时报错。
type Exception report
message java.util.NoSuchElementException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.util.NoSuchElementException com.paipai.webframework.dispatcher.PaiPaiDispatcher.serviceAction(PaiPaiDispatcher.java:713) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) com.paipai.webframework.filter.PaiPaiDispatcherFilter.doFilter(PaiPaiDispatcherFilter.java:175) org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
root cause
java.util.NoSuchElementException java.util.ArrayList$Itr.next(ArrayList.java:834) webbench.web.action.WebBenchAction.QueryTaskDetail(WebBenchAction.java:167) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
代码:
else{ jsonRootMap.put("ret", 0); jsonRootMap.put("msg", "查询任务成功。"); /*解析返回包*/ Iterator<WebBenchTask> i = webbenchtasklist.iterator(); while (i.hasNext()){ jsonTaskMap.put("TaskId", i.next().getTaskId()); jsonTaskMap.put("User", i.next().getUser()); jsonTaskMap.put("Ip", i.next().getIp());
问题原因:
i.next()每执行一次,游标后移以为。上述循环造成越界;
解决办法:
Iterator<WebBenchTask> i = webbenchtasklist.iterator(); while (i.hasNext()){ WebBenchTask task = i.next(); jsonTaskMap.put("TaskId", task.getTaskId()); jsonTaskMap.put("User", task.getUser()); jsonTaskMap.put("Ip", task.getIp()); jsonTaskMap.put("Url", task.getUrl());
时间: 2024-10-12 04:03:07