首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

求解:java.lang.IndexOutOfBoundsException: Index: 一, Size: 1

2011-11-09 
求解:java.lang.IndexOutOfBoundsException: Index: 1, Size: 1我用Hibernate查询:hql select u.email,

求解:java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
我用Hibernate查询:
hql = "select u.email, u.password from ApplicantPO as u where u.username=?";
  query = sessionH.createQuery(hql);
  query.setString(0, Username);

  list.clear();
  list = query.list();
  System.out.println("list.size() = " + list.size());

  if(list.size()>0){
  this.setEmail(list.get(0).toString().trim()); //给email赋值
  System.out.println("查到的email为:"+list.get(0).toString().trim());
  this.setUserPassword(list.get(1).toString().trim()); //给userPassword赋值
  }
  HibernateServiceProvider.closeSession();

得到的是这样的结果:
list.size() = 1
查到的email为:[Ljava.lang.Object;@13cebda
2011-7-26 21:32:36 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet default threw exception
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at rims.action.GetPasswordAction.checkUser(GetPasswordAction.java:133)
at rims.action.GetPasswordAction.validate(GetPasswordAction.java:153)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:200)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

麻烦大家指点一二~

[解决办法]
list.get(0).toString().trim()
[解决办法]
数组越界吧

热点排行