2 pengzhihao3399 pengzhihao3399 于 2014.10.23 11:10 提问

怎么遍历泛型list呢?
List<Article> art=articlebiz.findartbyname(cacs);
            /*List<Article> art=ad.findArticleByName(cacs);*/
            System.out.println("查询到art的值为:"+art);
        if (art.size()>0) {
            System.out.println("准备foreach循环遍历。。。。");
            for (Article article : art) {
                System.out.println("开始foreach循环遍历。。。。");
                System.out.println(article.getComment());
                System.out.println("结束foreach循环。。。");
            }`

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to org.blog.qhp.domain.Article
开始进入action
Action接收到值:tom
进入文章查询daotom
select * from article where FK_BLOG_ID IN (select PK_BLOG_ID from blog where blog_name='tom')
Hibernate:
select
*
from
article
where
FK_BLOG_ID IN (
select
PK_BLOG_ID
from
blog
where
blog_name='tom'
)
biz层接收到用户名:tom
查询到art的值为:[[Ljava.lang.Object;@e1d32e]
准备foreach循环遍历。。。。

at org.blog.qhp.action.IndexAction.show(IndexAction.java:56)
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 com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)

at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

好像说什么类型不能转换什么的`

1个回答

feiyun0112
feiyun0112   Rxr 2014.10.23 11:34

看看articlebiz.findartbyname的返回类型

pengzhihao3399
pengzhihao3399 对的啊,,,就是 List<Article> org.blog.qhp.biz.ArticleBiz.findartbyname(String name)
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
List集合泛型的应用和遍历
本文简介了List集合的泛型的添加和遍历的方法@Test public void demo1(){ List list = new LinkedList(); list.add("aaa"); list.add("bbb"); list.add("ccc"); //因为使用了泛型,只能在list中添加String类型元素 //遍历list方法---三种 //第一种list是有序的通过
java遍历泛型的方法
Java中有三种方法来遍历泛型,主要为: 1.for循环遍历 2.iterator遍历 3.foreach遍历 package com.gmail.lsgjzhuwei; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.junit.Test; public
使用泛型后的List集合类型的三种遍历方式
我们常用的集合类型有三种基本类型:List,Set和Map类型,其中运用泛型过后的这三种类型当中,List有三种遍历方式,Set和Map有两种遍历方式,而List这三种方式当中包含了Set和Map的另外两种遍历方式,因此我们以List为例. 遍历泛型List集合的三种方法包括普通for循环,迭代器和增强for循环,其中普通for循环是List所特有的: List有以下三种集合类可以实现这三种遍
泛型Map的遍历
1、这种是按照map里边存放的顺序依次取值的,取值的方法有两种: (1) for (Map.Entry, Object> entry : map1.entrySet()) { system.out.println(entry.getKey()); } (2) private Map, Object> handleParams(Map, Object> params)
JAVA的泛型 && JAVA的几种for循环方式
泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数。这种参数类型可以用在类、接口和方法的创建中,分别称为泛型类、泛型接口、泛型方法。         在没有泛型的情况的下,通过对类型Object的引用来实现参数的“任意化”,带来的缺点是要做显式的强制类型转换,而这种转换是要求开发者对实际参数类型可以预知的情况下进行的。对于强制类型转换错误的情况,编译器可能不提示错误,在运行的时候才
Asp.Net中List泛型数组的参数传递和遍历(示例源码)
调用代码:              IList csj1=Sql_List();  // 把处理返回的list数组赋值给csj1              string csj_str="";              foreach (int i in csj1)              {                 csj_str+= i.ToString() + ",
lua遍历调用C#泛型List、IEnumberable、Dictionary
在使用lua的时候,我们经常需要调用遍历调用C#中的泛型结构(诸如List、IEnumberable、Dictionary)。 在LUA中最通用的遍历方法是针对table的调用,所以我们可以将C#中的数据结构转换为lua table
list泛型数组遍历,根据指定索引取出数据
List listDouble = new List(); for (int i = 0; i             {                 listDouble.Add(i + 1);//给list泛型数组增加值             } for (
ArrayList存储字符串并遍历。要求加入泛型,并用增强for遍历。
package cn.itcast_01; import java.util.ArrayList; import java.util.Iterator; /*  * ArrayList存储字符串并遍历。要求加入泛型,并用增强for遍历。  * A:迭代器  * B:普通for  * C:增强for  */ public class ArrayListDemo {
Map.Entry 遍历之泛型
上一遍文档讲到Map.Entry的遍历map方法,但没有使用泛型,导致每次遍历获取元素时要强制转换。下面看一版使用泛型的代码示例import java.util.*; public class AnswerTo19{ public static void main(String args[]){ List list = new ArrayList(); Map map=new Hash