Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2006, 01:07 PM
Authorized User
 
Join Date: May 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default java.lang.ArrayIndexOutOfBoundsException

Hi,

I am getting a java.lang.ArrayIndexOutOfBoundsException: 4 error and don't know why its happening.

Code:
 <% for (int i = 0 ; i <= FacultyTeam.length ; i++) {%>
            <tr bgcolor="#FFC164" class="bodytext">
              <td bordercolor="#FF0000"><input name="checkbox" type="checkbox" value="checkbox"></td>
              <td height="26" bordercolor="#FF0000"><div align="center"><%=FacultyTeam[i].getSectionNo()%></div></td>
              <td><div align="left"><%=FacultyTeam[i].getTeamName()%></div></td>
              <td><div align="left"><a href="faculty_outstanding_student.jsp">Incomplete</a></div></td>

           <% for (int j = i; j <= FacultyTeam.length ; j++)  { %>
           <% if ((j+1<FacultyTeam.length) || (j+1==FacultyTeam.length)) { %>
           <% if (FacultyTeam[j].getTeamName().equals(FacultyTeam[j].getTeamName())) { %>
                   <td><div align="left"><%=FacultyTeam[j].getStudentName()%>, </div></td>
   <% }} else { %> <td><div align="left"><%=FacultyTeam[j].getStudentName()%> <%i=j; j=FacultyTeam.length;}%> </div></td> <% } %>
            </tr>
               <% } %>
Here is the error message:

Code:
org.apache.jasper.JasperException: Exception in JSP: /resources/faculty_manage_team.jsp:94

91:            <% if ((j+1<FacultyTeam.length) || (j+1==FacultyTeam.length)) { %>
92:            <% if (FacultyTeam[j].getTeamName().equals(FacultyTeam[j].getTeamName())) { %>
93:                    <td><div align="left"><%=FacultyTeam[j].getStudentName()%>, </div></td>
94:    <% }} else { %> <td><div align="left"><%=FacultyTeam[j].getStudentName()%> <%i=j; j=FacultyTeam.length;}%> </div></td> <% } %>
95:             </tr>
96:                <% } %>
97:             </table>
Where am I going wrong?

 
Old July 1st, 2006, 07:21 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Arrays go from 0 to length-1. Your for loop should not loop over the index FacultyTeam.length. Therefore change the for loop to use a less-than sign, not a less-than-or-equal-to.

Jon Emerson
http://www.jonemerson.net/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Root Cause:java.lang.NoSuchMethodError: java.util. anees81 JSP Basics 3 March 1st, 2011 08:55 AM
java.lang.OutOfMemoryError: Java heap space meetkotresh J2EE 1 February 2nd, 2008 01:52 AM
java.lang.StackOverflowError ravi_sri24 XSLT 31 February 1st, 2008 09:48 AM
java.lang.IllegalStateException: priyatowin J2EE 0 September 13th, 2006 10:57 PM
java.lang.Runtime mudasirw J2EE 1 August 2nd, 2005 02:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.