一个测试用例如下: public String showAllUserinfo(){
ActionContext atx = ActionContext.getContext();
List array = userMgr.showAllUserinfo();
List result = null;
User u = new User();
for (Iterator iter = array.iterator(); iter.hasNext(); ) { //知道这里还是调试通过的
u = (User)iter.next(); //问题所在之处,无法调试下去...
result.add(u);
}
atx.getParameters().put("userinfo", result);
return SUCCESS;
}
u = (User)iter.next(); 这句为何会错呢?
报错的代码为:
Source not found for InvocationTargetException.<init>(Throwable) line: not available
控制台报错代码:
2009-4-28 17:31:38 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet default threw exception
java.lang.ClassCastException: [Ljava.lang.Object;
at com.gc.action.LoginAction.showAllUserinfo(LoginAction.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)在线等!!!谢谢
ActionContext atx = ActionContext.getContext();
List array = userMgr.showAllUserinfo();
List result = null;
User u = new User();
for (Iterator iter = array.iterator(); iter.hasNext(); ) { //知道这里还是调试通过的
u = (User)iter.next(); //问题所在之处,无法调试下去...
result.add(u);
}
atx.getParameters().put("userinfo", result);
return SUCCESS;
}
u = (User)iter.next(); 这句为何会错呢?
报错的代码为:
Source not found for InvocationTargetException.<init>(Throwable) line: not available
控制台报错代码:
2009-4-28 17:31:38 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet default threw exception
java.lang.ClassCastException: [Ljava.lang.Object;
at com.gc.action.LoginAction.showAllUserinfo(LoginAction.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)在线等!!!谢谢
解决方案 »
- 百分求助,在线等,关于JasperReport中String类型输出总是为null
- 急。。js树形菜单,节点值传递问题
- 求一动态修改数据库表结构Demo
- 有关hibernate的事物
- 急呀!!!!!!!!!!!!!!!!!!!!!hibernate学习路径!
- 紧急求助!!!WSWS3192E: 错误:WebServicesFault 的映射异常。 <(404)Not Found>WebServicesFault
- J2EE程序的性能优化
- 请教一个关于java函数的问题~~~~~~~~~~~!!!!!!!!!!!
- 关于一个加密类的改进跟使用问题(急!!)
- linux系统下tomcat部署项目报错BeanCreatException
- 一道华为的笔试题
- 关于单例的一个问题
直接写User u = null;
后面不变就好。
java.lang.ClassCastException: [Ljava.lang.Object;
是类型转换出错了。。[Ljava.lang.Object;提示为这是一个Object 对象数组,你把它转换为User当然出错了。
改为这样应该可以 User[] users = iter.next();(这能不能对,楼主试试吧)但,返回对象为数组不会错
他是反回一个Objcet类型的
1楼:问题依存2楼:问题依存,类型依然不匹配。3楼:问题依存。5楼:Objcet[] Objcet= iter.next(); 提示 Objcet cannot be resolved to a type6楼:问题依存。
请检查这里面的返回类型是否为User集合, 建议使用泛型技术, 返回List<User>结果集, 这样可以避免不必要的转型错误.
如图,调试到Object[] obj = (Object[])iter.next();可以通过,但到:u = (User)iter.next(); 就调试错误了。
再加看看,如果再报异常先检查你的方法返回的集合里面是否有值,且类型是否匹配,再检查你导迭代器的包是否正确。