at java.util.ArrayList.get(Unknown Source)
at com.xmj.action.Index_frontAction.clientadd(Index_frontAction.java:106)
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 org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
以上是报错!以下是出错的地方,貌似是下标越界了,可是我不懂,不会改,请大家帮帮忙吧……
Client client1=(Client)clientDao.query("from Client where clientName='"+clientName+"' and certificate='"+certificate+"' and flag='1'").get(0);
if(client1==null){
Client client=new Client();
client.setClientName(clientName);
client.setSex(sex);
client.setClientAge(Integer.parseInt(clientAge));
client.setRace(race);
client.setTel(tel);
client.setCertificate(certificate);
client.setFlag(1); //表示已经在消费,登记在案
//下面的暂时不实现
client.setTime(new Date());
client.setOrdered(1); //表示已经登记
clientDao.add(client);
request.setAttribute("s", "登记成功!尊敬的客户您可以登录之后进行订餐订房操作!");
request.setAttribute("backUrl", "deskIndex.jsp");
}else{
request.setAttribute("s", "登记失败!尊敬的客户您已经登记过!!");
request.setAttribute("backUrl", "clientLoad.jsp");
}
11 个解决方案
#1
Client client1=(Client)clientDao.query("from Client where lientName='"+clientName+"' and certificate='"+certificate+"' and flag='1'").get(0);
这里应该是空的,但你又在get(0),所以报错
你查下有没有数据。。。
可能是没有数据引起的
#2
Client client1=(Client)clientDao.query("from Client where clientName='"+clientName+"' and certificate='"+certificate+"' and flag='1'").get(0);
改为
ArrayList<Client> list = clientDao.query("from Client where clientName='"+clientName+"' and certificate='"+certificate+"' and flag='1'");
if(list.size()>0){
Client client1=list.get(0);
}
改为
ArrayList<Client> list = clientDao.query("from Client where clientName='"+clientName+"' and certificate='"+certificate+"' and flag='1'");
if(list.size()>0){
Client client1=list.get(0);
}
#3
LS应该是正确的
#4
数组越界了。在取数组内容时先判断是否为null,是否有你要取的下标
#5
我看了下,是没有数据造成的,那要怎么办啊?
#6
哪一行?
没有数据?if呗...
#7
2L + 1
#8
按照2楼的方式改改试试看啊,要大胆的尝试。。。
#9
list里面是不是空?若是空你还去list.get(0)当然就报上面的错误了。
#10
clientDao.query返回的集合空。
#11
嗯,是list为空
解决啦,谢谢大家
解决啦,谢谢大家
#1
Client client1=(Client)clientDao.query("from Client where lientName='"+clientName+"' and certificate='"+certificate+"' and flag='1'").get(0);
这里应该是空的,但你又在get(0),所以报错
你查下有没有数据。。。
可能是没有数据引起的
#2
Client client1=(Client)clientDao.query("from Client where clientName='"+clientName+"' and certificate='"+certificate+"' and flag='1'").get(0);
改为
ArrayList<Client> list = clientDao.query("from Client where clientName='"+clientName+"' and certificate='"+certificate+"' and flag='1'");
if(list.size()>0){
Client client1=list.get(0);
}
改为
ArrayList<Client> list = clientDao.query("from Client where clientName='"+clientName+"' and certificate='"+certificate+"' and flag='1'");
if(list.size()>0){
Client client1=list.get(0);
}
#3
LS应该是正确的
#4
数组越界了。在取数组内容时先判断是否为null,是否有你要取的下标
#5
我看了下,是没有数据造成的,那要怎么办啊?
#6
哪一行?
没有数据?if呗...
#7
2L + 1
#8
按照2楼的方式改改试试看啊,要大胆的尝试。。。
#9
list里面是不是空?若是空你还去list.get(0)当然就报上面的错误了。
#10
clientDao.query返回的集合空。
#11
嗯,是list为空
解决啦,谢谢大家
解决啦,谢谢大家