1. ホーム

java lang ClassCastException java util ArrayList cannot be able to be.

2022-02-10 16:40:04
<パス

1. エラーの説明

java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map at service.impl.BillServiceImpl.exportBillExcel( BillServiceImpl.java:336) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java. lang.reflect.Method.invoke(Method.java:606) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java :317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org. springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop. framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52) at org.springframework.aop. framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor. ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework. ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy. invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy46.exportBillExcel(Unknown Source) at controller.BillController. exportBillExcel(BillController.java:159) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect. NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke( DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.web.method.support. InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) at org.springframework.web.method.support.InvocableHandlerMethod. invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation. ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method. annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749) at org.springframework.web.servlet .mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689) at org.springframework.web abstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) at org.springframework.web.servlet. DispatcherServlet.doDispatch(DispatcherServlet.java:938) at org.springframework.web.servlet. DispatcherServlet.java:870) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org. springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) at javax.servlet.http. java:620) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet. service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server. WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.skycloud.oa.





2. エラーの原因

List<List<Map<String,Object>>> itemList = new ArrayList<List<Map<String,Object>>>>();





Map<String,Object> map=(Map<String, Object>) itemList.get(i);





      itemListはListコレクションであり、その中にListが入っているため、List<List>をMapに強制するとエラーになります。


3. ソリューション

List<List<Map<String,Object>>> itemList = new ArrayList<List<Map<String,Object>>>>();for(int j=0;j& lt;itemList.size();j++){ for(int i = 0 ; i<itemList.get(j).size();i++) { Map<String,Object> map=(Map<String, Object>) itemList .get(j).get(i); }}








私の師匠である神様のAIチュートリアルをもう一回紹介しましょう。基本はゼロ! 簡単に理解できる! 面白くてユーモアがある そしてまた、黄色の段落で! ぜひ、AIチームに参加してみてくださいね https://blog.csdn.net/jiangjunshow