Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1477
  • Last Modified:

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

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
saleemkhan
Asked:
saleemkhan
  • 8
  • 6
  • 4
1 Solution
 
TimYatesCommented:
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
 
TimYatesCommented:
Arrays go from "0", not "1"

0
 
jimmackCommented:
Arrays in Java are indexed from 0.

As Tim pointed out (when he should be working ;-))
0
Industry Leaders: 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!

 
TimYatesCommented:
> 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
 
saleemkhanAuthor Commented:
yes i know Java arrays are zero based.

please read my whole question and let me solution..
0
 
TimYatesCommented:
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
 
saleemkhanAuthor Commented:
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
 
TimYatesCommented:
>  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
 
TimYatesCommented:
> 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
 
TimYatesCommented:
> As Tim pointed out (when he should be working ;-))

hehe ;-P
0
 
jimmackCommented:
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
 
saleemkhanAuthor Commented:
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
 
jimmackCommented:
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
 
jimmackCommented:
Sorry:

<PARAM NAME="PIE_STYLE_<%=i%>" VALUE="<%= (String)pieStyle.elementAt(i) %>">
0
 
TimYatesCommented:
>  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
 
saleemkhanAuthor Commented:
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
 
jimmackCommented:
Oops.  Sorry.  That should be:

(String)pieStyle.get(i)
0
 
jimmackCommented:
;-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 8
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now