Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error 500: Server caught unhandled exception from servlet [JSP 1.2 Processor]: 8

Posted on 2003-12-02
18
Medium Priority
?
1,476 Views
Last Modified: 2008-03-04
hi all,
 i am getting
Error 500: Server caught unhandled exception from servlet [JSP 1.2 Processor]: 8

i found in console is

java.lang.ArrayIndexOutOfBoundsException: 8
 


here is my query

//declaring the variable
String[] colLabels=new String[8];
pieStyle[1]="RED";
pieStyle[2]="BLUE";
pieStyle[3]="ORANGE";
pieStyle[4]="YELLOW";
pieStyle[5]="#00FF33";
pieStyle[6]="#996633";
pieStyle[7]="GREEN";
pieStyle[8]="violet";


<%
s = conn.createStatement();
rs= s.executeQuery("select * from tablename where flag = 'active' and id="+ request.getParameter("id"));
%>

// counting number of rows and storing in variable colNumber
<%while (rs.next())
{
colNumber++;
}
%>

//Assigning the values to the colLables array

<%while (rs.next())
{
for(int z=1;z<=colNumber;z++)
{
colLabels[z]=rs.getString("tod_col1");
rs.next();
}
}
%>

//printing the applet parameters


<%
for(int i=1;i<=colNumber-1;i++)
{
%>
<PARAM NAME="PIE_NAME_<%=i%>" VALUE="<%=colLabels%>">
<PARAM NAME="PIE_STYLE_<%=i%>" VALUE="<%=pieStyle%>">
<%
}
%>

my code works fine if the number of rows returned will be 7.
sometimes my query return more than 320 rows.
then i am getting the error
Error 500: Server caught unhandled exception from servlet [JSP 1.2 Processor]: 8

so i tried to declare an array of the number of rows

 //declaring the variable
<%
String[] colLabels=new String[colNumber];
String[] pieStyle=new String[colNumber];
%>

same error server caught undandled exception.
 now  i tried like below

String[] colLabels=new String[458];
String[] pieStyle=new String[458];


and assigning values
pieStyle[1]="#CCCC33";
pieStyle[2]="#99CCFF";
pieStyle[3]="#CC66CC";
pieStyle[4]="#CC3366";
..... etc till
pieStyle[50]="#9966FF";

 so its works fine if i have 50 records.
instead of doing this statically
 i thought of  assign randly generated colors to an array pieStyle[] . instead of assinging them static.?hwo to do this?
or is there any other solution please let me know.?
waiting for expert solution


0
Comment
Question by:saleemkhan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 4
18 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9857069
String[] colLabels=new String[8];
pieStyle[0]="RED";
pieStyle[1]="BLUE";
pieStyle[2]="ORANGE";
pieStyle[3]="YELLOW";
pieStyle[4]="#00FF33";
pieStyle[5]="#996633";
pieStyle[6]="GREEN";
pieStyle[7]="violet";
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9857071
Arrays go from "0", not "1"

0
 
LVL 15

Expert Comment

by:jimmack
ID: 9857074
Arrays in Java are indexed from 0.

As Tim pointed out (when he should be working ;-))
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 35

Expert Comment

by:TimYates
ID: 9857075
> String[] pieStyle=new String[458];

here, you are making an array WAY bigger than the amount you use, so you never fall off the end :-)

Hope this helps :-)

Tim
0
 

Author Comment

by:saleemkhan
ID: 9857081
yes i know Java arrays are zero based.

please read my whole question and let me solution..
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9857091
Do what you are doing:

---------

<%
String[] colLabels=new String[colNumber];
String[] pieStyle=new String[colNumber];
%>

---------

but then go from "0" not "1":

---------

// and assigning values START AT ZERO
pieStyle[0]="#CCCC33";
pieStyle[1]="#99CCFF";

----------

If that doesn't work, you're going to have to post your code, and not just snippets of it...

Tim
0
 

Author Comment

by:saleemkhan
ID: 9857097
hi timyates,
 why i declare array like below is because sometimes my resultset will result 460 records from table.
i know its not prefrerred to use such a big array.

String[] pieStyle=new String[458];
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9857098
>  yes i know Java arrays are zero based.

How do you expect this to work then?

String[] colLabels=new String[8];
pieStyle[1]="RED";
pieStyle[2]="BLUE";
pieStyle[3]="ORANGE";
pieStyle[4]="YELLOW";
pieStyle[5]="#00FF33";
pieStyle[6]="#996633";
pieStyle[7]="GREEN";
pieStyle[8]="violet";  // THIS WILL THROW AN ARRAYINDEXOUTOFBOUNDSEXCEPTION
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9857102
> i know its not prefrerred to use such a big array.

That's not a big array...I use 100K arrays with no problems...

I think you are right trying to size your array to the colNumber variable
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9857103
> As Tim pointed out (when he should be working ;-))

hehe ;-P
0
 
LVL 15

Accepted Solution

by:
jimmack earned 500 total points
ID: 9857119
Use an ArrayList to store the values instead.  This will grow to allow the additions as necessary.

Random colours...

        ArrayList pieStyle = new ArrayList();
        for (int i = 0; i < 100; i++)
        {
           StringBuffer colString = new StringBuffer(Integer.toHexString((int)(Math.random() * 0xFFFFFF)));
           while (colString.length() < 6)
           {
              colString.insert(0, "0");
           }
           colString.insert(0, "#");
           pieStyle.add(colString.toString());
        }
0
 

Author Comment

by:saleemkhan
ID: 9857120
hi timyates,
 i will like this

---------

<%
String[] colLabels=new String[colNumber];
String[] pieStyle=new String[colNumber];
%>

---------
 till now ok.no problem.

// and assigning values START AT ZERO
pieStyle[0]="#CCCC33";
pieStyle[1]="#99CCFF";

this will be ok no probelm.

suppose if my query results 350 records i have assign  350 colors to the array statically.
// and assigning values START AT ZERO
pieStyle[0]="#CCCC33";
pieStyle[1]="#99CCFF";
... etc
 ------ till
pieStyle[349]="#99CCFF";

so thats why in my frist post itself
i mentioned below please refer this again.

 i thought of  assign randly generated colors to an array pieStyle[] . instead of assinging them static.?hwo to do this?
or is there any other solution please let me know.?
waiting for expert solution
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9857127
Then you need:

<%
for(int i=1;i<=colNumber-1;i++)
{
%>
<PARAM NAME="PIE_NAME_<%=i%>" VALUE="<%=colLabels%>">
<PARAM NAME="PIE_STYLE_<%=i%>" VALUE="<%= pieStyle.elementAt(i) %>">
<%
}
%>
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9857130
Sorry:

<PARAM NAME="PIE_STYLE_<%=i%>" VALUE="<%= (String)pieStyle.elementAt(i) %>">
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9857181
>  i thought of  assign randly generated colors to an array pieStyle[] . instead of assinging them static.?hwo to do this?

Ahhhhhhh....

Sorry, the title of this question, and most of the Q at the top are about an ArrayOutOfBoundsException....

All you wanted was a way to randomly create colors?
0
 

Author Comment

by:saleemkhan
ID: 9857222
hi,
  i am sorry that title of the quetion is wrong but in my first post itself  i ask the experts

>  i thought of  assign randly generated colors to an array pieStyle[] . instead of assinging them static.?hwo to do this?

from now onwards i will take care of title of the question.
i am sorry for this.
 i tried  the comment

<%
for(int i=1;i<=colNumber-1;i++)
{
%>
<PARAM NAME="PIE_NAME_<%=i%>" VALUE="<%=colLabels%>">
<PARAM NAME="PIE_STYLE_<%=i%>" VALUE="<%= (String)pieStyle.elementAt(i) %>">
<%
}
%>


i am getting error the method elementAt(int) is undefined for the type java.util.ArryList


0
 
LVL 15

Expert Comment

by:jimmack
ID: 9857231
Oops.  Sorry.  That should be:

(String)pieStyle.get(i)
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9857314
;-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question