日期:2014-05-18  浏览次数:20759 次

求解: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()
------解决方案--------------------
数组越界