Solved

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

Posted on 2003-12-02
18
1,463 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
  • 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A Short Story about the Best File Recovery Software – Acronis True Image 2017
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now