数组越界
首先我知道是越界,关键怎么解决,跪求高手!在线等java.lang.IndexOutOfBoundsException: Index: 118, Size: 118
java.util.ArrayList.RangeCheck(ArrayList.java:547)
java.util.ArrayList.get(ArrayList.java:322)
app.poozf.actions.SmileAction.data3(SmileAction.java:639)
app.poozf.actions.SmileAction.execute(SmileAction.java:405)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
app.util.EncodingFilter.doFilter(EncodingFilter.java:33)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.32 logs.
--------------------编程问答-------------------- 越界就是因为index超过实际list的size了,你说怎么解决? --------------------编程问答-------------------- 要知道怎么解决还问吗?具体怎么改 --------------------编程问答-------------------- Index: 118, Size: 118
好像是在取最后一个元素的时候错了 --------------------编程问答-------------------- 把你代码贴出来吧。 --------------------编程问答--------------------
}else if (tabcode.equals("A0004")) { //流动性风险季报
String[] pig = getpigdate(pigdate);
String subrno = subbrno(brno);
list = ssbo.selectA0004(pig[0], subrno);
sqlist = ssbo.selectA0004(pig[1], subrno);//上期
nclist = ssbo.selectA0004(pig[3], subrno);//年初
tqlist = ssbo.selectA0004(pig[2], subrno);//同期
list1 = this.data3(list,sqlist,nclist,tqlist);
System.out.println("-------->>>>>List1A0004 值: "+list1);
request.setAttribute("list", list1);
return mapping.findForward("successA0004");
-----------------------------------------------------------------------------------
public List<CreditReport> data3(List<CreditReport> list,List<CreditReport> sqlist,
List<CreditReport> nclist, List<CreditReport> tqlist) {
List<CreditReport> list1 = new ArrayList<CreditReport>();
for (int i = 0; i < list.size(); i++) {
CreditReport cr = list.get(i);
CreditReport cr1 = sqlist.get(i);
CreditReport cr2 = nclist.get(i);
CreditReport cr3 = tqlist.get(i);
double dValue=0;
CreditReport cr8 = new CreditReport();
cr8.setName1(cr.getName1());
cr8.setName2(cr.getName2());
for (int j = 0; j < 10; j++) {
PoozfConMete.setValue(cr8, 7 * j + 1, PoozfConMete.getValue(cr,j + 1));
PoozfConMete.setValue(cr8, 7 * j + 2, PoozfConMete.getValue(cr,j + 1)- PoozfConMete.getValue(cr1, j + 1));
PoozfConMete.setValue(cr8, 7 * j + 3, PoozfConMete.getValue(cr,j + 1)- PoozfConMete.getValue(cr2, j + 1));
PoozfConMete.setValue(cr8, 7 * j + 4, PoozfConMete.getValue(cr,j + 1)- PoozfConMete.getValue(cr3, j + 1));
//同比增长率=本期数÷同期数×100%
if(PoozfConMete.getValue(cr3, j + 1)==0){
dValue=0;
}else{
dValue=(PoozfConMete.getValue(cr,j + 1)/PoozfConMete.getValue(cr3, j + 1))*100;
}
PoozfConMete.setValue(cr8, 7 * j + 5, dValue);
//环比增长速度=本期数/上期数*100%
if(PoozfConMete.getValue(cr1, j + 1)==0){
dValue=0;
}else{
dValue=(PoozfConMete.getValue(cr,j + 1)/PoozfConMete.getValue(cr1, j + 1))*100;
}
PoozfConMete.setValue(cr8, 7 * j + 6, dValue);
//定基比
if(PoozfConMete.getValue(cr2, j + 1)==0){
dValue=0;
}else{
dValue=(PoozfConMete.getValue(cr,j + 1)/PoozfConMete.getValue(cr2, j + 1))*100;
}
PoozfConMete.setValue(cr8, 7 * j + 7, dValue);
}
list1.add(cr8);
}
return list1;
}
------------------------------------------------------------------------------------
BO
public List<CreditReport> selectA0004 (String pigdate, String subrno){
Connection conn = null;
List <CreditReport> list = new ArrayList <CreditReport>();
try{
conn = DataSourceUtils.getConnection(DataSourceUtils.getPool());
SmileDAO ssdo = new SmileDAO();
list = ssdo.selectA0004(conn, pigdate, subrno);
}catch(Exception e){
e.printStackTrace();
}finally{
DataSourceUtils.closeConnection(conn);
}
return list;
}
-------------dao
public List<CreditReport>selectA0004(Connection conn,String pigdate, String subrno){
PreparedStatement ps = null;
ResultSet rs =null;
List<CreditReport> list = new ArrayList<CreditReport>();
CreditReport cr= null;
String sql="select t1.brname,t2.ldxqk,t2.hxfzycd,t1.brno from itp_bctl t1 left outer join ("
+"select a.brno,case when c.bal=0 then 0 else (a.syrzjsr+b.bal)/c.bal*100 end as ldxqk,case when f.bwbhj=0 then 0 else (d.bal+e.ynys)/f.bwbhj*100 end as hxfzycd from"
+"(select brno,syrzjsr from g2100 where pigdate='"+pigdate+"' and reprownum=29)a"
+",(select brno,zj-cr-erzqr-brzssr-syrzjsr as bal from g2100 where pigdate='"+pigdate+"' and reprownum=30)b"
+",(select brno,decimal(sum(cr+erzqr+brzssr+syrzjsr),16,2) as bal from g2100 where pigdate='"+pigdate+"' and reprownum in (1,11) group by brno)c"
+",(select brno,zj-cr-erzqr-brzssr-syrzjsr as bal from g2100 where pigdate='"+pigdate+"' and reprownum in (20,22))d"
+",(select brno,ynys from g2100 where pigdate='"+pigdate+"' and reprownum=30)e"
+",(select brno,bwbhj from g0100 where pigdate='20110350' and reprownum=67)f"
+" where a.brno=b.brno and a.brno=c.brno and a.brno=d.brno and a.brno=e.brno and a.brno=f.brno)t2 on t1.brno=t2.brno where t1.brno in ("+subrno+")"
+" order by t1.brno";
System.out.println("----------->打印selectA0004 sql 语句"+sql);
try{
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
cr =new CreditReport();
cr.setName1(rs.getString(1));
cr.setValue1(rs.getDouble(2));
cr.setValue2(rs.getDouble(3));
cr.setName2(rs.getString(4));
list.add(cr);
}
}catch(Exception e){
e.getMessage();
}finally{
DataSourceUtils.closeResultSetStatement(rs, ps);
}
return list;
} --------------------编程问答-------------------- OMG. 这样看不出啥问题呀。
还是自己调试下吧。在越界的地方做个判断就行了。 --------------------编程问答-------------------- this.data3(list,sqlist,nclist,tqlist);
好像是上面后三个list(sqlist,nclist,tqlist)与第一个list的长度不一致 --------------------编程问答-------------------- 对 是的,怎么解决啊。
-------->>>>>>>list 值: 233
-------->>>>>sqlist 值: 232
-------->>>>>tqlist 值: 118
-------->>>>>nclist 值: 118 --------------------编程问答-------------------- 这几个list都是通过
selectA0004 (String pigdate, String subrno)
方法得到的吧,
而他们的区别就是pigdate不一样而已,
这个是由于数据库里对应的记录数不一样,
在代码里似乎只能做判断,防止抛异常,但还是解决不了根本问题呀 --------------------编程问答-------------------- 你说的很对, 我还是解决不了这个问题。
哥们 我的msn a_nie@live.cn qq 708892491 。或者留下你的。 --------------------编程问答-------------------- Index: 118, Size: 118
Size 118时候index最多117.因为下标从0开始
你打个断点.找到报错的这句话,看看你的什么地方逻辑错了
补充:Java , Web 开发