MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » 求解:java.lang.IndexOutOfBoundsException: Index

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

www.MyException.Cn  网友分享于:2013-11-10  浏览:637次
求解: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()
------解决方案--------------------
数组越界

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有