类型转换异常

J2EE 码拜 4年前 (2017-04-30) 559次浏览
StringBuffer hql2 = new StringBuffer(
					"select roomId from DailyDataColdWater where DateTime>"2017-04-07 00:00:00" and TotalUsed!=0 group by roomId,TotalUsed,LeftQuantity having count(roomId)=3");
			List<String> list2 = new ArrayList<String>();
			list2 = waterCtrlMonLogManager.find(hql2.toString());
			StringBuffer hql3 = new StringBuffer(
					"select roomId from DailyDataDelEle where DateTime>"2017-04-07 00:00:00" and UsedEle!=0 group by roomId,UsedEle having count(roomId)<3");
			List<String> list3 = new ArrayList<String>();
			list3 = waterCtrlMonLogManager.find(hql3.toString());
			System.out.println("交集为" + getSection(list2, list3).toString());
			System.out.println("交集为" + getSection(list2, list3).size());
public static List<String> getSection(List<String> list2, List<String> list3) {
		System.out.println(list2.toString());
		System.out.println(list3.toString());
		List<String> result = new ArrayList<String>();
		for (String str : list2) {
			for (String str_final : list3) {
				if (str.equals(str_final)) {
					result.add(str);
				}
			}
		}
		return result;
	}
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
	at com.changgong.cardwater.web.WaterCtrlMonLogAction.getSection(WaterCtrlMonLogAction.java:472)
	at com.changgong.cardwater.web.WaterCtrlMonLogAction.list(WaterCtrlMonLogAction.java:159)
	at org.springside.core.web.StrutsEntityAction.index(StrutsEntityAction.java:111)
	at org.springside.core.web.StrutsEntityAction.unspecified(StrutsEntityAction.java:260)
	at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:249)
	at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
	at com.java.changgong.filter.OnlineFilter.doFilter(OnlineFilter.java:60)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
	at org.extremecomponents.table.filter.AbstractExportFilter.doFilter(AbstractExportFilter.java:49)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
	at com.changgong.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:28)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
	at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:834)
	at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
	at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)
	at java.lang.Thread.run(Thread.java:619)

明明没有Integer类型的值,报了类型转换异常,也是不懂了。

解决方案

20

java.lang.Integer cannot be cast to java.lang.String…Integer类型不能转为String..
for (String str : list2) {           //–异常位置–异常显示这一行报错?
你的roomId在数据库中是什么类型的?

10

取交集和并集,List本身有方法的,retainAll() 方法,但你这报的异常是类型转换失败

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明类型转换异常
喜欢 (0)
[1034331897@qq.com]
分享 (0)