Solved

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

Posted on 2003-12-02
18
1,471 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 125 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Apache server configuration 7 92
jersey maven project error 7 145
getting Http 404 error in jsp forms 8 85
Suggestion on WebSite Template Sites 6 116
This article was initially published on Monitis Blog, you can read it here . When it comes to deciding which approach to website performance monitoring is best for your business, unfortunately, like so many options in life . . . it depends. In t…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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