1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

Discussion in 'JSP' started by baktha.thalapathy, May 29, 2010.

  1. baktha.thalapathy

    baktha.thalapathy New Member

    Joined:
    May 29, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    i run the below i got the error
    Code:
    <%
           //}
           String runT = "",filename = "",da  = "";
           PreparedStatement psPagination = null;
           ResultSet rsPagination = null;
    
       String home = System.getProperty ("user.dir") + "/domains/domain1/docroot/CKML";
      String folder2 = "/KML";
      String cid = "Cid"+ id;
     // String oid = "Oid"+ Objectid;
      String EA = "/tripReports";
      FileWriter fw ;
      File fi = new File(home + folder2 + "/CKBI" + "/"+cid + EA);
      fi.mkdirs();
      long Total=0;
      String disHour="";
      String disMinu="";
      String disSec="";
      int nano=0;
     ArrayList arr = new ArrayList();
     ArrayList arr1 = new ArrayList();
     ArrayList arr2 = new ArrayList();
     long totalTimeInMillis=0;
     Set<String> dates = new HashSet<String>();
     ArrayList<Integer> l=new ArrayList<Integer>();
     ArrayList<Integer> m=new ArrayList<Integer>();
     ArrayList<Long> n=new ArrayList<Long>();
     Map <String, Long> datesAndTotal = new HashMap<String, Long>();
     DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
     Timestamp t1 = null;
     Timestamp t2 = null;
     int count  = 0;
     long sum = 0;
     long result=0;
     long results=0;
     //int check = 0;
     int checkA = 0, totKm = 0;
     String presentKey="";
           if (from != null && from != "")
           {
         try
         {
                    filename = fi.getPath() + "/" + dis+".xls";
                     fw = new FileWriter(filename);
                     fw.append("Navyani Innovations Inc.");
                     fw.append('\n');
                     fw.append('\n');
                     fw.append("Trip report for " + dis);
                     fw.append('\n');
                     fw.append('\n');
                     fw.append("Date");
                     fw.append('\t');
                     fw.append("Run Time");
                     fw.append('\t');
                     fw.append("Distance Traveled");
    
    
                String d = from + " 00:00:59";
                String d1 = to + " 23:59:59";
        
              
                String sqlPagination ="SELECT gpstime from xydata a inner join fm4features f on a.ID=f.ID where a.objectId= '" + Objectid + "'  AND a.clientId = '" + id + "' AND a.gpstime >= '"+d+"'  AND a.gpstime <= '"+d1+"' AND f.DataId='1' AND f.value = '1'";
                psPagination = connection.prepareStatement(sqlPagination);
                rsPagination = psPagination.executeQuery();
               while ( rsPagination.next() )
             {
    
                String gpstime = rsPagination.getString("GpsTime");
                if (dates.add(gpstime))
                {
                   Date d2 = rsPagination.getDate(1);
                   t2 = rsPagination.getTimestamp(1);
    
                   count++;
                   if (t1 == null )
                   {
                      nano = t2.getSeconds();
                      System.out.println(t2);
                      System.out.println(nano);
                    }
    
                   else
                   {
    
                      totalTimeInMillis = (t2.getTime() - t1.getTime()) / 1000;
                       String dateString = df.format(d2);
                               System.out.println("GPSTime " +gpstime+ " Time in seconds: " + totalTimeInMillis+ " seconds.");
                      if (datesAndTotal.containsKey(dateString))
                      {
                         m.add((totalTimeInMillis < 80) ? (int) totalTimeInMillis : (int) (totalTimeInMillis % 60));
    
                          for (int y=0; y<m.size();)
                          {
                          sum+=m.get(y);
                          y++;
                        }
                          sum+= (datesAndTotal.get(dateString))/-1;
                          System.out.println(sum);
    
                      }
                      datesAndTotal.put(dateString, sum);
                   }
                   t1 = t2;
    
                }
    
    
    
    
             }
                         List mapKeys = new ArrayList(datesAndTotal.keySet());
                         List mapValues = new ArrayList(datesAndTotal.values());
                         Collections.sort(mapValues);
                          Collections.sort(mapKeys);
                        LinkedHashMap Maps = new LinkedHashMap();
                        Iterator valueIt = mapValues.iterator();
                        while (valueIt.hasNext()) {
                        Object val = valueIt.next();
                         Iterator keyIt = mapKeys.iterator();
                        while (keyIt.hasNext()) {
                        Object key = keyIt.next();
                        if (datesAndTotal.get(key).toString().equals(val.toString()))
                        {
                        datesAndTotal.remove(key);
                        mapKeys.remove(key);
                        Maps.put(key, val);
                        break;
                                   }
                              }
                        }
    
    
                        Iterator it1 = Maps.entrySet().iterator();
                        String prevKey="";
                        while (it1.hasNext()) {
                           Map.Entry entry = (Map.Entry) it1.next();
                           presentKey=(String)entry.getKey();
                           if(prevKey.length()==0){
                                   System.out.println(presentKey+"=>"+entry.getValue());
                                   results=(Long) entry.getValue()+60;
                                   System.out.println(results);
                                 arr1.add(presentKey);
                                 int hours = (int) (results / 3600),
                                     remainder = (int) (results % 3600),
                                     minutes = remainder / 60,
                                     seconds = remainder % 60;
    
                                 disHour = (hours < 10 ? "0" : "") + hours;
                                 disMinu = (minutes < 10 ? "0" : "") + minutes;
                                 disSec = (seconds < 10 ? "0" : "") + seconds;
                                if (count < 2)
                                         {
                                            int se = Integer.parseInt(disSec);
                                            String min = (t2.getSeconds() < 10 ? "0" : "") + t2.getSeconds();
                                            System.out.println("00" + ":" +  min + ":" + se + " hh:mm:ss");
                                         }
                                    System.out.println(disHour +":"+ disMinu+":"+disSec+ " hh:mm:ss");
                                    arr.add(disHour + ":" + disMinu + ":"+ disSec);
    
    
                           }
                           else{
                                   Long present=(Long)entry.getValue();
                                   Long prev=(Long) Maps.get(prevKey);
                                   result=(Long) (present - prev)+30;
                                   System.out.println(""+presentKey+"=>"+result);
                                  System.out.println(result);
                                  arr1.add(presentKey);
                                 int hours = (int) (result / 3600),
                                     remainder = (int) (result % 3600),
                                     minutes = remainder / 60,
                                     seconds = remainder % 60;
    
                                 disHour = (hours < 10 ? "0" : "") + hours;
                                 disMinu = (minutes < 10 ? "0" : "") + minutes;
                                 disSec = (seconds < 10 ? "0" : "") + seconds;
                                       if (count < 2)
                                         {
                                           // int se = Integer.parseInt(disSec);
                                          //  String min = (t2.getSeconds() < 10 ? "0" : "") + t2.getSeconds();
                                           // System.out.println("00" + ":" +  min + ":" + se + " hh:mm:ss");
                                         }
    
                                     System.out.println(disHour +":"+ disMinu+":"+disSec+ " hh:mm:ss");
                                    arr.add(disHour + ":" + disMinu + ":"+ disSec);
    
                                   }
                           prevKey=(String)presentKey;
    
    
                          n.add(result);
                         }
    
                          n.add(results);
                   ++checkA;
                   totalKM = pip.tripReport.AddDrive(id, Objectid, presentKey,presentKey,connection);
                        fw.append('\n');
                        fw.append(presentKey+" ");
                        fw.append('\t');
    
                             for (int i=0; i<n.size();)
                          {
                              Total+=n.get(i);
                              i++;
    
                          }
                             System.out.println(Total);
                                     int hours = (int) (Total / 3600),
                                     remainder = (int) (Total % 3600),
                                     minutes = remainder / 60,
                                     seconds = remainder % 60;
    
                                  disHour = (hours < 10 ? "0" : "") + hours;
                                  disMinu = (minutes < 10 ? "0" : "") + minutes;
                                   disSec = (seconds < 10 ? "0" : "") + seconds;
                                       if (count < 2)
                                         {
                                            //int se = Integer.parseInt(disSec);
                                           // String min = (t2.getSeconds() < 10 ? "0" : "") + t2.getSeconds();
                                           // System.out.println("00" + ":" +  min + ":" + se + " hh:mm:ss");
                                         }
    
                                     System.out.println("Total Time=>" +disHour +":"+ disMinu+":"+disSec+ " hh:mm:ss");
                  fw.append('\n');
                  fw.append('\n');
                  fw.append("Total ");
                  fw.append('\t');
                  fw.append(disHour + ":" + disMinu + ":" + disSec + " hh:mm:ss");
                  fw.flush();
                  fw.close();
    
          }  catch(Exception e){e.printStackTrace();}
                                        finally
                                        {
                                          stmt.close();
                                          psPagination.close();
                                          rsPagination.close();
                                          connection.close();
                                        }
         }
           %>
    <div id="RightPane">
    
    <div id="TopPane">
    <div id="track">
        <center>
    <table>
     <th id="disreports" style="background-color: white;">Vehicle/ID:</th>
     <th id="disreports" style="background-color: white;">Date</th>
     <th id="disreports" style="background-color: white;">Run Time</th>
     <th id="disreports" style="background-color: white;">Distance Traveled </th>
    
    <%
    
    
           if (from != null && from !="")
           {
     for(int i = 0; i < arr.size(); )
    {
    %>
    
    
    
            <tr>
    
            <td id="disreports" style="background-color:#dae7f6;"><%=dis%></td>
            <td id="disreports" style="background-color:#dae7f6;"><%=arr1.get(i)%>&nbsp; &nbsp;</td>
            <td id="disreports" style="background-color:#dae7f6;"><font color="Black">&nbsp;<%=arr.get(i) %>  </font><br></td>
           <td id="disreports" style="background-color:#dae7f6;"><font color="Black">&nbsp;<%=arr2.get(i) %>  </font> km<br></td>
    
        </tr>
    
    
    <%i++;} arr.clear(); arr1.clear();arr2.clear();  %>
    <tr>
    
        <td></td>
         <td id="disreports" style="background-color: white;">Total Time: </td>
         <td id="disreports" style="background-color: white;"><%=disHour+ ":" +disMinu+ ":" +disSec %></td>
         <td id="disreports" style="background-color:#dae7f6;"><b><font color="Black">&nbsp;<%=totKm %> </font> km  </b><br></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td id="disreports" style="background-color: white;">Save as</td>
        <td id="disreports" style="background-color:#dae7f6;"><font color="Black">&nbsp;<a href="#" onclick="download();" style="text-decoration: none;"><%=dis%>.xls</a> </font><br></td>
    </tr>
    
    <% } %>
    </table>
     </center>
    <br>
    
    
    </div>
    </div>
    
    error
    Code:
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
            at java.util.ArrayList.RangeCheck(ArrayList.java:547)
            at java.util.ArrayList.get(ArrayList.java:322)
            at org.apache.jsp.tripreport_jsp._jspService(tripreport_jsp.java from :862)
            at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
            at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
            at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:366)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
            at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:431)
            at org.apache.catalina.core.StandardWrapperValve.preInvoke(StandardWrapperValve.java:462)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:139)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:186)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
            at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
            at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:187)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:142)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
            at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:242)
            at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
            at com.sun.grizzly.http.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:633)
            at com.sun.grizzly.http.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:570)
            at com.sun.grizzly.http.DefaultProcessorTask.process(DefaultProcessorTask.java:827)
            at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:152)
            at com.sun.enterprise.v3.services.impl.GlassfishProtocolChain.executeProtocolFilter(GlassfishProtocolChain.java:71)
            at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
            at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
            at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
            at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
            at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
            at com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:325)
            at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:184)
    
    
    anybody having idea please help me

    thanks in advance
     

Share This Page