ArrayIndexOutOfBounds error

Hi all, when running the following code, I get an ArrayIndexOutOfBounds: 255 error. I should note that getHist() returns an int[3][255]. I'm sure there's something simple that I should be doing, but I don't know what it is. Any ideas?
private void saveFile() {
        BufferedImage bi = leftPanel.img;
        int[][] image_data = getHist(bi);
                //new int[3][256];
        //image_data = getHist(bi);
        //System.out.println(image_data.length);
        JFileChooser saveChoose = new JFileChooser();
        int result = saveChoose.showSaveDialog(this);
        if (result == JFileChooser.CANCEL_OPTION) return;
        if(result == JFileChooser.APPROVE_OPTION)
        try{
            FileWriter fw = new FileWriter(saveChoose.getSelectedFile());
            BufferedWriter bw = new BufferedWriter(fw);
           for(int i = 0; i < image_data.length; i++){
               for(int j = 0; j < image_data.length; j++){
//System.out.println(image_data[i].length);
if(j == (image_data[i].length - 1)){
//System.out.println("Condition ok " + image_data[i].length );
bw.write(String.valueOf(image_data[j][i]) );
System.out.println("Data ok");
bw.newLine();
else{
bw.write( String.valueOf(image_data[i]) + "\t");
bw.close();
}catch(Exception e){
System.out.println("Error: " + e);
Thanks,
Joe

I generalized my example so it can write to System.out or a BufferedWriter:
import java.io.*;
public class Example {
    static void print(Appendable out, int[][] m) throws IOException {
        String lineSeparator = System.getProperty("line.separator");
        for(int i=0; i<m.length; ++i) {
            for (int j=0; j < m.length; j++) {
out.append(String.valueOf(m[i][j])).append("\t");
out.append(lineSeparator);
public static void main(String[] args) throws IOException {
int[][] data = {
{0,2,4,6,8},
{1,3,5,7,9},
print(System.out, data);
BufferedWriter bw = new BufferedWriter(new FileWriter("junk.txt"));
try {
print(bw, data);
} finally {
bw.close();

Similar Messages

  • Getting an arrayindexoutofbounds error when trying to run mail app

    here is the code, it compiles fine, but when i run it, i get an array
    index out of bunds error
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class SimpleSender {
      public static void main (String args[]) throws Exception {
        String host = args[0];
        String from = args[1];
        String to = args[2];
        // Get system properties
        Properties props = System.getProperties();
        // Setup mail server
        props.put("mail.smtp.host", host);
        // Get session
        Session session = Session.getDefaultInstance(props, null);
        // Define message
        MimeMessage message = new MimeMessage(session);
        // Set the from address
        message.setFrom(new InternetAddress(from));
        // Set the to address
        message.addRecipient(Message.RecipientType.TO,
          new InternetAddress(to));
        // Set the subject
        message.setSubject("Hello JavaMail");
        // Set the content
        message.setText("Welcome to JavaMail");
        // Send message
        Transport.send(message);
    }this is the error message:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
    at SimpleSender.main(SimpleSender.java:7)

    Which is line 7? I'll bet it's one of these three:  String host = args[0];
      String from = args[1];
      String to = args[2];which would mean you didn't pass enough command-line arguments to your program.

  • Null Pointer Exception when trying to access Portlet Context

    I am using the JSR_168_Support.zip, that was downloaded from the BEA site to implement
    the Portal technology utilizing the JSR_168 standard. I followed the instructions
    in the INSTALL.TXT file that is included in the zip file on replacing some of
    the supporting weblogic jars with the zip jars. When I added the below servlet
    tag to my web.xml, I got an ArrayIndexOutOfBounds error when the server started
    up. I figured that there was some sort of problem with the load-on-startup parameter,
    so I commented it out. After this, the server started up fine and the log stated
    that the PortletHttpServer had initialized.
    <servlet>
    <servlet-name>com.bea.portlet.server.PortletHttpServer</servlet-name>
    <servlet-class>com.bea.portlet.server.PortletHttpServer</servlet-class>
    <!-- <load-on-startup>1</load-on-startup> -->
    </servlet>
    As per the INSTALL.TXT, I superclassed all jsp's with the PortletJSPBase class.
    When I bring up the portal, the portlet that contains the jsp with the following
    code,
    PortletContext portletContext = portletConfig.getPortletContext();
    javax.portlet.PortletURL msActionUrl = renderResponse.createActionURL();
    Stack Trace:
    Error opening /portlet/Customer/CustomerSubmit.jsp.
    The source of this error is java.lang.NullPointerException at jsp_servlet._portlet._customer.__customersubmit._jspService(CustomerSubmit.jsp:11)
    at com.bea.portlet.jsp.PortletJspBase.service(PortletJspBase.java:110) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:431)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.wlw.netui.pageflow.PageFlowJspFilter.doFilter(PageFlowJspFilter.java:101)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.p13n.servlets.PortalServletFilter.doFilter(PortalServletFilter.java:313)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:597)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:409)
    at com.bea.netuix.servlets.controls.content.JspContent.beginRender(JspContent.java:460)
    at com.bea.netuix.nf.ControlLifecycle$7.visit(ControlLifecycle.java:424) at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:427)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:172) at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:95)
    at com.bea.netuix.nf.Lifecycle.run(Lifecycle.java:380) at com.bea.netuix.nf.UIControl.render(UIControl.java:580)
    at com.bea.netuix.servlets.controls.PresentationContext.render(PresentationContext.java:341)
    at com.bea.netuix.servlets.util.RenderToolkit.renderChild(RenderToolkit.java:123)
    at com.bea.netuix.servlets.jsp.taglib.RenderChild.doStartTag(RenderChild.java:58)
    at jsp_servlet._framework._skeletons._default.__flowlayout._jspService(flowlayout.jsp:32)
    at com.bea.portlet.jsp.PortletJspBase.service(PortletJspBase.java:110) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:431)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.wlw.netui.pageflow.PageFlowJspFilter.doFilter(PageFlowJspFilter.java:101)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.p13n.servlets.PortalServletFilter.doFilter(PortalServletFilter.java:313)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:597)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:409)
    at com.bea.netuix.servlets.controls.JspRenderer.renderAlt(JspRenderer.java:187)
    at com.bea.netuix.servlets.controls.JspRenderer.beginRender(JspRenderer.java:90)
    at com.bea.netuix.nf.ControlLifecycle$7.visit(ControlLifecycle.java:420) at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:427)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:172) at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:95)
    at com.bea.netuix.nf.Lifecycle.run(Lifecycle.java:380) at com.bea.netuix.nf.UIControl.render(UIControl.java:580)
    at com.bea.netuix.servlets.controls.PresentationContext.render(PresentationContext.java:341)
    at com.bea.netuix.servlets.util.RenderToolkit.renderChild(RenderToolkit.java:123)
    at com.bea.netuix.servlets.jsp.taglib.RenderChild.doStartTag(RenderChild.java:58)
    at jsp_servlet._framework._skeletons._default.__gridlayout._jspService(gridlayout.jsp:32)
    at com.bea.portlet.jsp.PortletJspBase.service(PortletJspBase.java:110) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.wlw.netui.pageflow.PageFlowJspFilter.doFilter(PageFlowJspFilter.java:101)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.p13n.servlets.PortalServletFilter.doFilter(PortalServletFilter.java:313)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:597)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:409)
    at com.bea.netuix.servlets.controls.JspRenderer.renderAlt(JspRenderer.java:187)
    at com.bea.netuix.servlets.controls.JspRenderer.beginRender(JspRenderer.java:90)
    at com.bea.netuix.nf.ControlLifecycle$7.visit(ControlLifecycle.java:420) at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:427)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:172) at com.bea.netuix.nf.Lifecycle.runOutbound(Lifecycle.java:220)
    at com.bea.netuix.nf.Lifecycle.run(Lifecycle.java:158) at com.bea.netuix.servlets.manager.UIServlet.runLifecycle(UIServlet.java:363)
    at com.bea.netuix.servlets.manager.UIServlet.service(UIServlet.java:207) at com.bea.netuix.servlets.manager.PortalServlet.service(PortalServlet.java:584)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.p13n.servlets.PortalServletFilter.doFilter(PortalServletFilter.java:313)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6316)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118) at
    weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3622)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2569)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

    Could you also post the original ArrayIndexOutOfBounds stack trace?
    Thanks
    Subbu
    Frank Valcone said the following on 12/12/2003 01:13 PM:
    I am using the JSR_168_Support.zip, that was downloaded from the BEA site to implement
    the Portal technology utilizing the JSR_168 standard. I followed the instructions
    in the INSTALL.TXT file that is included in the zip file on replacing some of
    the supporting weblogic jars with the zip jars. When I added the below servlet
    tag to my web.xml, I got an ArrayIndexOutOfBounds error when the server started
    up. I figured that there was some sort of problem with the load-on-startup parameter,
    so I commented it out. After this, the server started up fine and the log stated
    that the PortletHttpServer had initialized.
    <servlet>
    <servlet-name>com.bea.portlet.server.PortletHttpServer</servlet-name>
    <servlet-class>com.bea.portlet.server.PortletHttpServer</servlet-class>
    <!-- <load-on-startup>1</load-on-startup> -->
    </servlet>
    As per the INSTALL.TXT, I superclassed all jsp's with the PortletJSPBase class.
    When I bring up the portal, the portlet that contains the jsp with the following
    code,
    PortletContext portletContext = portletConfig.getPortletContext();
    javax.portlet.PortletURL msActionUrl = renderResponse.createActionURL();
    Stack Trace:
    Error opening /portlet/Customer/CustomerSubmit.jsp.
    The source of this error is java.lang.NullPointerException at jsp_servlet._portlet._customer.__customersubmit._jspService(CustomerSubmit.jsp:11)
    at com.bea.portlet.jsp.PortletJspBase.service(PortletJspBase.java:110) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:431)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.wlw.netui.pageflow.PageFlowJspFilter.doFilter(PageFlowJspFilter.java:101)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.p13n.servlets.PortalServletFilter.doFilter(PortalServletFilter.java:313)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:597)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:409)
    at com.bea.netuix.servlets.controls.content.JspContent.beginRender(JspContent.java:460)
    at com.bea.netuix.nf.ControlLifecycle$7.visit(ControlLifecycle.java:424) at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:427)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:172) at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:95)
    at com.bea.netuix.nf.Lifecycle.run(Lifecycle.java:380) at com.bea.netuix.nf.UIControl.render(UIControl.java:580)
    at com.bea.netuix.servlets.controls.PresentationContext.render(PresentationContext.java:341)
    at com.bea.netuix.servlets.util.RenderToolkit.renderChild(RenderToolkit.java:123)
    at com.bea.netuix.servlets.jsp.taglib.RenderChild.doStartTag(RenderChild.java:58)
    at jsp_servlet._framework._skeletons._default.__flowlayout._jspService(flowlayout.jsp:32)
    at com.bea.portlet.jsp.PortletJspBase.service(PortletJspBase.java:110) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:431)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.wlw.netui.pageflow.PageFlowJspFilter.doFilter(PageFlowJspFilter.java:101)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.p13n.servlets.PortalServletFilter.doFilter(PortalServletFilter.java:313)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:597)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:409)
    at com.bea.netuix.servlets.controls.JspRenderer.renderAlt(JspRenderer.java:187)
    at com.bea.netuix.servlets.controls.JspRenderer.beginRender(JspRenderer.java:90)
    at com.bea.netuix.nf.ControlLifecycle$7.visit(ControlLifecycle.java:420) at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:427)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:172) at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:95)
    at com.bea.netuix.nf.Lifecycle.run(Lifecycle.java:380) at com.bea.netuix.nf.UIControl.render(UIControl.java:580)
    at com.bea.netuix.servlets.controls.PresentationContext.render(PresentationContext.java:341)
    at com.bea.netuix.servlets.util.RenderToolkit.renderChild(RenderToolkit.java:123)
    at com.bea.netuix.servlets.jsp.taglib.RenderChild.doStartTag(RenderChild.java:58)
    at jsp_servlet._framework._skeletons._default.__gridlayout._jspService(gridlayout.jsp:32)
    at com.bea.portlet.jsp.PortletJspBase.service(PortletJspBase.java:110) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.wlw.netui.pageflow.PageFlowJspFilter.doFilter(PageFlowJspFilter.java:101)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.p13n.servlets.PortalServletFilter.doFilter(PortalServletFilter.java:313)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:597)
    at weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:409)
    at com.bea.netuix.servlets.controls.JspRenderer.renderAlt(JspRenderer.java:187)
    at com.bea.netuix.servlets.controls.JspRenderer.beginRender(JspRenderer.java:90)
    at com.bea.netuix.nf.ControlLifecycle$7.visit(ControlLifecycle.java:420) at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:427)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:436)
    at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:172) at com.bea.netuix.nf.Lifecycle.runOutbound(Lifecycle.java:220)
    at com.bea.netuix.nf.Lifecycle.run(Lifecycle.java:158) at com.bea.netuix.servlets.manager.UIServlet.runLifecycle(UIServlet.java:363)
    at com.bea.netuix.servlets.manager.UIServlet.service(UIServlet.java:207) at com.bea.netuix.servlets.manager.PortalServlet.service(PortalServlet.java:584)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.p13n.servlets.PortalServletFilter.doFilter(PortalServletFilter.java:313)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6316)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118) at
    weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3622)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2569)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

  • Retrieving data from an ArrayList and presenting them in a JSP

    Dear Fellow Java Developers:
    I am developing a catalogue site that would give the user the option of viewing items on a JSP page. The thing is, a user may request to view a certain item of which there are several varieties, for example "shirts". There may be 20 different varieties, and the catalogue page would present the 20 different shirts on the page. However, I want to give the user the option of either viewing all the shirts on a single page, or view a certain number at a time, and view the other shirts on a second or third JSP page.
    See the following link as an example:
    http://www.eddiebauer.com/eb/cat_default.asp?nv=2|21472|9&tid=&c=&sc=&cm_cg=&lp=n2f
    I am able to retrieve the data from the database, and present all of them on a JSP, however I am not sure how to implement the functionality so that they can be viewed a certain number at a time. So if I want to present say 12 items on a page and the database resultset brings back 30 items, I should be able to present the first 12 items on page1, the next 12 items on page2, and the remaining 6 items on page3. How would I do this? Below is my scriplet code that I use to retrieve information from the ArrayList that I retrieve from my database and present them in their entirety on a single JSP page:
    <table>
    <tr>
    <%String product=request.getParameter("item");
    ArrayList list=aBean.getCatalogueData(product);
    int j=0, n=2;
    for(Iterator i=list.iterator(); i.hasNext(); j++){
    if(j>n){
    out.print("</tr><tr>");
    j=0;
    Integer id=(Integer)i.next();
    String name=(String)i.next();
    String productURL=(String)i.next();
    out.print("a bunch of html with the above variables embedded inside")
    %>
    </tr>
    </table>
    where aBean is an instace of a JavaBean that retrieves the data from the Database.
    I have two ideas, because each iteration of the for loop represents one row from the database, I was thinking of introducing another int variable k that would be used to count all the iterations in the for loop, thus knowing the exact number. Once we had that value, we would then be able to determine if it was greater than or less than or equal to the maximum number of items we wanted to present on the JSP page( in this case 12). Once we had that value would then pass that value along to the next page and the for loop in each subsequent JSP page would continue from where the previous JSP page left off. The other option, would be to create a new ArrayList for each JSP page, where each JSP page would have an ArrayList that held all the items that it would present and that was it. Which approach is best? And more importantly, how would I implement it?
    Just wondering.
    Thanks in advance to all that reply.
    Sincerely;
    Fayyaz

    -You said to pass two parameters in the request,
    "start", and "count". The initial values for "start"
    would be zero, and the inital value for "count" would
    be the number of rows in the resultSet from the
    database, correct?Correct.
    -I am a little fuzzy about the following block of code
    you gave:
    //Set start and count for next page
    start += count; // If less than count left in array, send the number left to next next page
    count = ((start*3)+(count*3) < list.size()) ? (count) : ((list.size() - (start*3))/3)
    Could you explain the above block of code a little
    further please?Okay, first, I was using the ternary operators (boolean) ? val_if_true : val_if_false;
    This works like an if() else ; statement, where the expression before the ? represents the condition of the if statement, the result of the expression directly after the ? is returned if the condition is true, and the expression after the : is returned if the condition is false. These two statments below, one using the ternary ? : operators, and the other an if/else, do the same thing:
    count = ((start*3)+(count*3) < list.size()) ? (count) : ((list.size() - (start*3))/3);
    if ((start*3)+(count*3) < list.size()) count = count;
    else count = ((list.size() - (start*3))/3);Now, why all the multiplying by 3s? Because you store three values in your list for each product, 1) the product ID, 2) the product Name, and 3) the product URL. So to look at the third item, we need to be looking at the 9th,10th, and 11th values in the list.
    So I want to avoid an ArrayIndexOutOfBounds error from occuring if I try to access the List by an index greater than the size of the list. Since I am working with product numbers, and not the number of items stored in the list, I need to multiply by three, both the start and count, to make sure their sum does not exceed the value stored in the list. I test this with ((start*3)+(count*3) < list.size()) ?. It could have been done like: ((start + count) * 3 < list.size()) ?.
    So if this is true, the next page can begin looking through the list at the correct start position and find the number of items we want to display without overstepping the end of the list. So we can leave count the way it is.
    If this is false, then we want to change count so we will only traverse the number of products that are left in the list. To do this, we subtract where the next page is going to start looking in the list (start*3) from the total size of the list, and devide that by 3, to get the number of products left (which will be less then count. To do this, I used: ((list.size() - (start*3))/3), but I could have used: ((list.size()/3) - start).
    Does this explain it enough? I don't think I used the best math in the original post, and the line might be better written as:
    count = ((size + count)*3 < list.size()) ? (count) : ((list.size()/3) - start);All this math would be unnecessary if you made a ProductBean that stored the three values in it.
    >
    - You have the following code snippet:
    //Get the string to display this same JSP, but with new start and count
    String nextDisplayURL = encodeRedirectURL("thispage.jsp?start=" + start + "&count=" + count + "&item=" + product);
    %>
    <a href="<%=nextDisplayURL%>">Next Page</a>
    How would you do a previous page URL? Also, I need to
    place the "previous", "next" and the different page
    number values at the top of the JSP page, as in the
    following url:
    http://www.eddiebauer.com/eb/cat_default.asp?nv=2|21472
    9&tid=&c=&sc=&cm_cg=&lp=n2f
    How do I do this? I figure this might be a problem
    since I am processing the code in the middle of the
    page, and then I need to have these variables right at
    the top. Any suggestions?One way is to make new variable names, 'nextStart', 'previousStart', 'nextCount', 'previousCount'.
    Calculate these at the top, based on start and count, but leave the ints you use for start and count unchanged. You may want to store the count in the session rather than pass it along, if this is the case. Then you just worry about the start, or page number (start would be (page number - 1) * count. This would be better because the count for the last page will be less than the count on other pages, If we put the count in session we will remember that for previous pages...
    I think with the details I provided in this and previous post, you should be able to write the necessary code.
    >
    Thanks once again for all of your help, I really do
    appreciate the time and effort.
    Take care.
    Sincerely;
    Fayyaz

  • Setting text of a JLabel in an array

    Hey everyone. Im making a spreadsheet type program, but i have hit a brickwall and for the life of me i can't figure out what is wrong. What i'm trying to do, is check if the input in a cell is in the form e.g "=A3". Then i want the program to goto A3, copy what is in that cell and put it in the active cell. I've done the first bit, which is checking the input is in the form of e.g "=A3" using regex, and that works fine, the actual method doesn't seem to work for me, even though i manage to get the position of A3.
    Here is my code:
                   String s = inputdata.getText();
              String regexp = "=[A-Z]{1,2}[1-9]{1}[0-9]*";
              if (s.matches(regexp)){
                   String temp =  s.substring(1,2);                    //extracts the letter from the regex
                   char letter = temp.charAt(0);                         //converts the extracted letter to char indirecting using charAt
                   String temp2 = s.substring(2);                         //extracts the number from the regex
                   int number = (int)temp2.charAt(0);                    //stores the number from the regex in a int variable this is the row number
                   System.out.println(temp);                              
                   System.out.println(temp2);
                   int ascii = (int)letter;                              //converts the char letter to its ASCII code
                   int i = ascii - 64;                                        //gets the number of the column
                   System.out.println(i);
                   String textHolder = cell[number].getText();     //gets the text in [row][column] typed in
                   System.out.println(textHolder);          
                   tempcell.setText(textHolder);                         //sets the text of the active cell to the contents of the cell reference entered.
              }I get an arrayindexoutofbounds error.
    i don't see why its an array index out of bounds. My array cells is size [51][31]. Tempcell is the current active cell determined by another method.
    Any ideas?
    Edited by: kev_x on Apr 30, 2008 6:28 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    When you get an index out of bounds error, it tells you what index it tried to access. Like:
    ArrayIndexOutOfBoundsException: -1That would mean that you tried to access index -1.
    So what does your error tell you?

  • Runtime exceptions - Help!

    Hello, it's little ol' me again with my little ol' password generator applet. It compiles fine, but when I run it, I get all kinds of runtime exceptions when I click on any of the checkboxes. I have pored over this code til I'm blue in the face. I personally see nothing wrong with the code, but I'll post it here in case any of you might spot something suspicious.
    // My Javafied Password Generator
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class PwGenerator extends JApplet
      private String pw;
      private JPanel centerPanel, northPanel, southPanel;
      private JComboBox numchars;
      private JCheckBox lettersUpper, lettersLower, numbers, specialChars;
      private JButton generate, reset;
      private JTextField textfield;
      private static int asciiRange[];
      private String pwLength[] = {"6", "7", "8", "9", "10", "11", "12"};
      private int lengthSelected;
      private JLabel pwLabel, numCharLabel;
      public void init()
        // instantiate widgets
        numCharLabel = new JLabel("Number of characters for password");
        numchars = new JComboBox(pwLength);
        lettersUpper = new JCheckBox("Uppercase letters");
        lettersLower = new JCheckBox("Lowercase letters");
        numbers = new JCheckBox("Numbers");
        specialChars = new JCheckBox("Special characters");
        generate = new JButton("Generate password");
        reset = new JButton("Clear");
        textfield = new JTextField(12);
        pwLabel = new JLabel("Your new password is: ");
        // add widgets to the content pane
        Container c = getContentPane();
        c.setLayout(new BorderLayout());
        centerPanel = new JPanel();
        centerPanel.setLayout(new GridLayout(3, 2));
        centerPanel.add(lettersUpper);
        centerPanel.add(lettersLower);
        centerPanel.add(numbers);
        centerPanel.add(specialChars);
        centerPanel.add(generate);
        centerPanel.add(reset);
        c.add(centerPanel, BorderLayout.CENTER);
        northPanel = new JPanel();
        northPanel.setLayout(new FlowLayout());
        northPanel.add(numCharLabel);
        northPanel.add(numchars);
        c.add(northPanel, BorderLayout.NORTH);
        southPanel = new JPanel();
        southPanel.setLayout(new FlowLayout());
        southPanel.add(pwLabel);
        southPanel.add(textfield);
        c.add(southPanel, BorderLayout.SOUTH);
      }  // end init
      public void start()
      // connect event handlers to the widgets
        numchars.addItemListener(new ItemListener() {
         public void itemStateChanged(ItemEvent e)
           lengthSelected = Integer.parseInt(pwLength[numchars.getSelectedIndex()]);
        CheckBoxHandler handler = new CheckBoxHandler();
        lettersUpper.addItemListener(handler);
        lettersLower.addItemListener(handler);
        numbers.addItemListener(handler);
        specialChars.addItemListener(handler);
        generate.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e)
           pw = generatePw(lengthSelected);
           textfield.setText(pw);
        reset.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e)
           textfield.setText("");
      } // end start---snip---
    private class CheckBoxHandler implements ItemListener
        public void itemStateChanged(ItemEvent e)
          if (e.getSource() == specialChars)
         if (e.getStateChange() == ItemEvent.SELECTED)
           for (int i=33, j=0; i<=47; i++, j++)
             asciiRange[j] = i;
           for (int i=58, j=asciiRange.length; i<=64; i++, j++)
             asciiRange[j] = i;
           for (int i=91, j=asciiRange.length; i<=96; i++, j++)
             asciiRange[j] = i;
           for (int i=123, j=asciiRange.length; i<=126; i++, j++)
             asciiRange[j] = i;
            } // end inner if
          } // end outer if
          if (e.getSource() == numbers)
         if (e.getStateChange() == ItemEvent.SELECTED)
           for (int i=48, j=asciiRange.length; i<=57; i++, j++)
             asciiRange[j] = i;
          if (e.getSource() == lettersUpper) 
         if (e.getStateChange() == ItemEvent.SELECTED)
           for (int i=65, j=asciiRange.length; i<=90; i++, j++)
             asciiRange[j] = i;
          if (e.getSource() == lettersLower)
         if (e.getStateChange() == ItemEvent.SELECTED)
           for (int i=97, j=asciiRange.length; i<=122; i++, j++)
             asciiRange[j] = i;
    }     Your help will be greatly appreciated like before.
    Syster Tara

    And as a prediction, I can see some ArrayIndexOutOfBounds errors in your near future.
    Starting j at j=asciiRange.length
    and then doing asciiRange[j] = i
    Remember an array is numbered from 0 to length-1
    And no, arrays don't grow dynamically.
    Cheers,
    evnafets

  • Random nbrs

    I try to prit out 10 random nbrs the nbrs are between (1,20)
    and I do not want that the program prints a nbr more than one time.
    when I run the program I get ArrayIndexOutOfBounds error.
    my problem: how do I avoid that the program dose not print
    out a nbr more than one time.
    class Nbrs
         public static void main(String[]atgs){
         int []v= new int[10];
         int []s= new int[10];
         for(int i=0; i<10; i++)
         v= ...//read random nbr (1,20);
         for(int k=0; k<v.length; k++){
         if(v[k]!=v[k+1]){
         s[k]=v[k];
         v[k]=v[k+1];
         for(int i=0; i<10; i++)
         System.out.println(s[i]);

    your ArrayIndexIndexOutOfBounds comes from this code
    k+1in your for loop, when the loop is at 9 and you do "9+1 (-> 10)", java can't find the 10th element of your array(because it is the 11th!! - 0,1,2,3,4,5,6,7,8,9,10)

  • Broken diagonals

    Hi all,
    I'm writing a code that schecks if a given square is a panmagical square. For this the sum of every row, the sum of every column and the sum of every diagonal has to be the same. This includes so called broken diagonals:
    http://en.wikipedia.org/wiki/Broken_diagonal
    These have givien me quite a lot of trouble. I've written a method, that in my amature view should work. Only thing is, it doesn't. I get an arrayIndexoutofbounds error while running. There is probably a simple solution for this, but I just don't see it. I'm totally inexperienced at programming, and help would be much appreciated.
    Here's the code:
    public static void checkBrokenDiagonals(int [][] matrix) {
        int [] som1 = new int [matrix.length - 1];    // Table containing sums of broken diagonals, with "matrix.length - 1" as number of broken diagonals in particular direction.
        int [] som2 = new int [matrix.length - 1];    // Table containing sums of broken diagonals, with "matrix.length - 1" as number of broken diagonals in particular direction.
        // For-loop running through all broken diagonals.
        for (int k = 0; k <matrix.length - 1; k++) {
            // Set start variables
            int i = k+1;                                               // Row variable
            int j = matrix.length;                                     // Column variable
          // For-loop running through all entries of one broken diagonal, in top-right to bottom-left direction of the diagonals.
          for(int l = 0;l < matrix.length;l++) {
                                                                                // Example: //  o x x x
            // Save entry to total of broken diagonal.                                      //  x x x o
            som1[k] = som1[k] + matrix[i][j];                                               //  x x o x
                                                                                            //  x o x x
            // Crawl through broken diagonal
            i++;
            j--;
            // If row variable at maximum --> continue at minimum.
            if (i == matrix.length) {
              i = 0;
              j = k;
            // If column variable at minimum --> continue at maximum.
            //if (j == k + 1) {
            //  j = k;
        for(int o = 0; o < matrix.length; o++) {
          System.out.println("De som van de " + (o + 1) + "e gebroken diagonaal is: " + som1[o]);
          int temp = som1[k];
          if (o > 0 && temp == som1[o - 1]) {
            System.out.println("Dit komt overeen met de voorgaande diagonaal.");
          else {
            if(o > 0) {
              System.out.println("Dit komt NIET overeen met de voorgaande diagonaal.");
          // For-loop running through all entries of one broken diagonal, in top-left to bottom-right direction of the diagonals.
            // Set start variables
            i = k + 1;                 // Row variable
            j = 0;                     // Column variable
          for(int p = 0;p < matrix.length;p++) {
                                                                                // Example: //  x x x o
            // Save entry to total of broken diagonal.                                      //  o x x x
            som2[k] = som2[k] + matrix[i][j];                                               //  x o x x
                                                                                            //  x x o x
            // Crawl through broken diagonal
            i++;
            j++;
            // If row variable at minimum --> continue at maximum.
            //if (i == matrix.length) {
            //  i = k;
            // If column variable at maximum --> continue at minimum.
            if (j == matrix.length - k - 1) {
              j = matrix.length - k;
              i = 0;
        }I hope some one will be so kind to point out my errors.

    At first glance you doesn't check all diagonals but I'm lazy to check completely...
    Anyway my vision of such code here, fell free to adopt to your naming and calls. Looks slightly shorter.
      int iLength = 4;
      int[][] ppiField = new int[ iLength ][ iLength ];
      // First type : top left to bottom right
      for( int top = 0; top < iLength; top++ )
        int x = top;
        int y = 0;
        int iSum = 0;
        for( int walk = 0; walk < iLength; walk++ )
          iSum += ppiField[ y ][ x ];
          x = ( x + 1 ) % iLength;
          y = ( y + 1 ) % iLength;
        // Here iSum == diagonal
      // Second type : top right to bottom left
      for( int top = 0; top < iLength; top++ )
        int x = top;
        int y = 0;
        int iSum = 0;
        for( int walk = 0; walk < iLength; walk++ )
          iSum += ppiField[ y ][ x ];
          x = ( 0 == x ) ? ( iLength - 1 ) : ( x - 1 );
          y = ( y + 1 ) % iLength;
        // Here iSum == diagonal
      }

  • Array count

    hi everyone,
    i'm just new to programming and i need some help from everyone that is willing to help me.
    what's the statement or code that's counting the values of an array?how can you do it?
    lets say i got 6 arrays and each has a diferent integer value.how can i write the code for having the totalvalue of the array?...keeping in mind that also there is into a for statement .....???.....

    lets say i got 6 arrays.....I hardly call this clearly defined. It seems the OP was simply using that as an example.
    You should always write code that will work for all situations. What if the requirements were changed so that the array needed to hold 10 numbers, wrong answer calculated. Or worse if the array was < 6 numbers long, ArrayIndexOutOfBounds error. Or maybe the code needs to be dynamic ie the user enters a value for how many numbers are to be held in the array. All these will fail with your hard coded 6.

  • Error: Failed to load script file; java.lang.ArrayIndexOutOfBound.Exception: 3184

    Script editor was working find when I last used it last week.  Tried to open a script today to make some changes and now I'm getting this error message.  I have uninstalled and re-installed editor, checked the compatibility mode and it wont open the script.  any ideas out there what the problem could be? need some trouble shooting help.
    Error:
    failed to load script file: java.lang.ArrayIndexOutOfBound.Expception: 3184
    Thanks
    Lora

    Hmmm....   I haven't seen that, but I can tell you what I would do if I were you.  This is kind of drastic, but the alternative may be a workstation reimage.
    Open the windows control panel, and open the add/remove programs snap in.
    Uninstall the CRS editor.
    Uninstall all the JRE instances you have.  They may be listed as something like Java (TM) update....   or they may appear as J2SE Runtime....   Check in the J's (it's alphabetical) and uninstall all of them.
    Reboot the machine.
    Download and reinstall Java 1.6.0.17   (This is what's running on my workstation right now, and it works with the editor).
    Reinstall the CRS editor
    Reboot the machine
    Try it and see if it behaves.  If it doesn't, you may need to rebuild the whole thing.

  • Getting error arrayindexoutofbound : 0 in extended VO

    Hi,
    I have extended view object ApInvPoShipmentsVO(added new columns), initially I was getting error 'each row in the query result columns must be mapped to a unique query attribute in the mapped entity columns'  somehow I was able to resolve it.
    But now while running the page I am getting Arrayindex.. 0 when trying to use/print a particular view attribute.
    Also other custom added columns are fetching bad values, whereas when I run the same in sql dev. it is fetching correct value
    I am badly stuck with this, any help will be very great full.
    Regards

    I have extended view object ApInvPoShipmentsVO(added new columns), initially I was getting error 'each row in the query result columns must be mapped to a unique query attribute in the mapped entity columns'  somehow I was able to resolve it.
    For this.. Please create transient attributes first(say column1,cloumn2 etc). Then modify your sql query to add your columns with names as exactly the same transient attribute name and then modify the transient attribute by checking the 'mapped to sql' check box.
    looks like the attribute mapping is distorted. Try the above step and check.

  • Re: Error starting weblogic (ArrayIndexOutOfBounds)

     

    You probably need to remove the
    <domain>/<your_server>/.wlnotdelete subdirectory. I know it says to not delete this, but this is how we got going again.

  • Index:0 Size:0 error for non administrator group

    Hello, I have some dasboards and webis that I want to run in the iPad, If I login as Administrator everything is fine, but if I login as any other user I get the error: Index:0 Size: 0 can anyone tell me what I am missing? 
    I already check the note 1836197 - MOB00082 index:0, Size:0 in SAP BI Mobile App when using a non administartor group member  But I still have the error.
    I have these:
    SAP BusinessObjects BI Platform 4.1 Support Pack 5
    Version: 14.1.5.1501
    In all Cases the assigned access level is Full Control ( just to try)
    User: Test
    Authentication Type: Enterprise
    Group: Mobile
    Category: Mobile
    User Security of the Goup Mobile with Full Control :
    Folder:  Root and  Prueba EDU
    Dashboard:   Ventas2015_prueba27Abr  (Inherited)
    Applications:  SAP BusinessObjects Mobile Extra: WebIntelligence, Dashboards, IDT, Universe Designer
    Category: Mobile and to the  Top-Level Security
    Folders
    Root folder:  (CMC-->Folders-->Manage-->Top-Level security-->All Folders-->Add principal 'Mobile' Group  -->Grant user view right)
    Folder for  Webi & Dashboard:  “Prueba EDU”
    Categories
      root categories: (CMC-->Categories-->Manage-->Top-Level security-->All Categories-->Add Principals and Add user 'Mobile'-->Assign Security-->Advanced tab-->Add/Remove Rights-->View objects-->Apply)
    Category Mobile:
    Applications:
    Dashboards
    SAP BusinessObjects Mobile
    IDT
    Universe design tool
    Web Intelligence
    Note 1783173
    Dashboard and Webi
    Login as Test:

    HI Erika,
    This is an unexpected error. This error belongs to ArrayIndexOutOfBound exception of Java framework - where the list of size is 0 or null and you try to access object on that list.
    Since this is a coding defect (which may or may not be resolved by changing configuration). Next steps - I would strongly recommend that you contact Product Support through the official channel .  http://support.sap.com/incident
    Regards,
    Ashutosh

  • Sender ADapter Monitor- ArrayIndexOutOfBOunds Exception

    Hi
    As me subject line reads,  I am getting an "ArrayIndeXOutofBOunds 9" exception at the sender adapter monitor logs in the RWB.
    I have an a<i>dapter monitor module</i> that picks up the file from the source  and pushes the file to a target directory based on some condition. I am able to see the file being pushed to the target directory but not able to view the "pipeline steps" in the message monitor.
    Do you think a restart of the server might fix the issue/ do you think there is a problem in my code. I have used just one array and i have checked that array if it is being accessed out of its bounds?
    Thanks
    krishna

    Hi,
    >>>>>ArrayIndeXOutofBOunds 9"
    looks like an error in code
    Regards,
    michal
    <a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a>

  • SQL statement in servlet giving error

    Please let me know if I need to post this on a different forum, but I thought it was applicable to here.
    First, let me preface this post by saying I've inserted hardcoded values at the DB (Oracle) level and it worked just fine, so most of the statement is sound. All the values inserted properly when testing it that way. Also, I've printed the SQL statement to the console and all looks ok there, too.
    Out of this, I'm getting an error citing the following:
    java.lang.ArrayIndexOutOfBoundsException
    also occasionally getting the following error:
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
    In my servlet, I'm attempting the following:
    prior to the insert statement, I'm retrieving the last row number to start the increment from as in:
    Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ResultSet rst = stmt.executeQuery("select CHANGE_CTRL_ID from CHANGE_CONTROL_USER order by CHANGE_CTRL_ID");
         rst.last();
         int lastRowNum = Integer.valueOf(rst.getString("CHANGE_CTRL_ID")).intValue();
         rst.close();
         stmt.close();
    ------------ then ------------------------------------------------
    String preparedQuery = "INSERT ALL " +
    "INTO CHANGE_CONTROL_USER " +
    "(CHANGE_CTRL_ID,REQUESTOR_NAME,REQUESTOR_EMAIL,BUS_CONTACT,DEPT,LOCATION,PHONE_NUM,DATE_REQ," +
    "BUSVP,VP_PHONE,VP_DATE,BRANCH,PRIORITY,OPS_MAN_CHG,OPS_MAN_PPCHAP,TRAIN_REQ," +
    "EXIST_SYS_FLD_CHG,BUS_RULES_CHG,NEW_CODING,NEW_BUS_RULE,NEW_SYS_FIELD,REQ_TYPE_OTHER,REQ_OTHER_SPECIFY,IMPACT_RE_COLL," +
    "IMPACT_DEF_LM,IMPACT_DEF_REC_NRE,IMPACT_AUDIT,IMPACT_PERS_COLL,IMPACT_DEF_FCL,IMPACT_BUS_TECH,IMPACT_LEGAL,IMPACT_PRIV_COLL," +
    "IMPACT_DEF_BKRUP_RE,IMPACT_DEC_SUPT,IMPACT_RISK_MGT,IMPACT_DEF_REO,IMPACT_DEF_BKRUP_NRE,IMPACT_QUALSVCS,IMPACT_INTERNAL_CTRL,IMPACT_DEF_WKFL," +
    "IMPACT_DEF_WKOUT,IMPACT_TRAIN_TPI,IMPACT_OTHER,IMPACT_DEF_MGT,IMPACT_DEF_TAX,IMPACT_VEND_MGT,IMPACT_DEF_CTRL,IMPACT_DEF_REC_RE," +
    "IMPACT_BUS_ADMIN,IMPACT_OTHER_SPECIFY,CHANGE_IN_KPMG,CHANGE_IN_OTS,CHANGE_IN_NFR,CHANGE_IN_ARR,CHANGE_IN_BRR, CHANGE_IN_PROC_IMP," +
    "CHANGE_IN_INT_CITI_POL,CHANGE_IN_OTHER,CHANGE_IN_OTHER_SPECIFY, CHANGE_INIT_DETAILS,REQ_INFO_DESCRIPT,REQ_INFO_EXPLAIN_CURRBUS,REQ_INFO_EXPLAIN_PROPOSED,REQ_BEN_PROP_BENEFIT,REQ_BEN_FIN_IMPLEMENT," +
    "REQ_BEN_OPS_IMPLEMENT,YES_FORM,VULN_ASSESS, CBA_CHG, RISK_ACCEPT,MARSITEM, GCCRFP, APP_COMPL_QUES,CAP_EXPEND)" +
    " VALUES (changecontrol_user_seq.nextval,?,?,?,?,?,?,to_date(?,'YYYY-MON-DD HH:MI:SS'),?,?,to_date(?,'YYYY-MON-DD HH:MI:SS'),?,?," + "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
    + "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
    + "INTO CHANGE_CONTROL_ADMIN "
    + "(AID,CHANGE_CTRL_ID,ADMNAME,CLOSEDATE,ACTIVE)"
    + "VALUES (changecontrol_admin_seq.nextval, changecontrol_user_seq.currval,NULL, NULL, -1)"
    + "SELECT object_name AS REQUESTOR_NAME FROM all_objects where rownum <= 1;";     
    also I've declared all the respective strings for the PreparedQuery statement.
    If you need to see those, here they are:
    PreparedStatement pstmt = connection.prepareStatement(preparedQuery);
                   // stmt = connection.stmt("INSERT INTO RMIS_USER VALUES (?,?,?,?,to_date(?,'YYYY-MON-DD HH:MI:SS'),?,?,?,?,to_date(?,'YYYY-MM-DD HH:MI:SS')");
              pstmt.setInt(1,++lastRowNum);
              pstmt.setString(2,reqName);
              pstmt.setString(3,reqemail);
              pstmt.setString(4,buscont);
              pstmt.setString(5,reqDept);
              pstmt.setString(6,reqLocale);
              pstmt.setString(7,phone_num);
              pstmt.setDate(8,dtreq);
              //pstmt.setCalendar(8,rtnow);
              pstmt.setString(9,busvp_email);
              pstmt.setString(10,vpphone);
              pstmt.setDate(11,dt);
              pstmt.setString(12,branch);
              pstmt.setString(13,priority);
              pstmt.setString(14,opsmanchg);
              pstmt.setString(15,opsmanppchap);
              pstmt.setString(16,train_req);
              pstmt.setString(17,reqexist_sys_fld_chg);
              pstmt.setString(18,reqbus_rules_chg);
              pstmt.setString(19,reqnew_coding);
              pstmt.setString(20,reqnewbus_rule );
              pstmt.setString(21,reqnew_sys_fld);
              pstmt.setString(22,reqother);
              pstmt.setString(23,req_other_specify);
              pstmt.setString(24,imp_recoll);
              pstmt.setString(25,imp_deflm);
              pstmt.setString(26,imp_defrecnre);
              pstmt.setString(27,imp_audit);
              pstmt.setString(28,imppers_coll);
              pstmt.setString(29,imp_deffcl);
              pstmt.setString(30,imp_bustech);
              pstmt.setString(31,imp_legal);
              pstmt.setString(32,imp_privcoll);
              pstmt.setString(33,imp_defbkre);
              pstmt.setString(34,imp_decsupt);
              pstmt.setString(35,imp_riskmgt);
              pstmt.setString(36,imp_defreo);
              pstmt.setString(37,imp_defbknre);
              pstmt.setString(38,imp_qualsvc);
              pstmt.setString(39,imp_intlctrl);
              pstmt.setString(40,imp_defwkfl);
              pstmt.setString(41,imp_defwkout);
              pstmt.setString(42,imp_trtpi);
              pstmt.setString(43,impact_other);
              pstmt.setString(44,imp_defmgt);
              pstmt.setString(45,imp_deftax);
              pstmt.setString(46,imp_vendmgt);
              pstmt.setString(47,imp_defctrl);
              pstmt.setString(48,imp_defrecre);
              pstmt.setString(49,imp_busadm);
              pstmt.setString(50,impact_other_specify);
              pstmt.setString(51,change_in_kpmg);
              pstmt.setString(52,change_in_ots);
              pstmt.setString(53,change_in_nfr);
              pstmt.setString(54,change_in_arr);
              pstmt.setString(55,change_in_brr);
              pstmt.setString(56,change_in_proc_imp);
              pstmt.setString(57,change_inter_citpol);
              pstmt.setString(58,change_in_other);
              pstmt.setString(59,change_in_other_specify);
              pstmt.setString(60,change_init_details);
              pstmt.setString(61,req_info_descript);
              pstmt.setString(62,req_info_explain_currbus);
              pstmt.setString63,req_info_explain_proposed);
              pstmt.setString(64,req_ben_prop_benefit);
              pstmt.setString(65,req_ben_fin_implement);
              pstmt.setString(66,req_ben_ops_implement);
              pstmt.setString(67,projyes);
              pstmt.setString(68,vulnass);
              pstmt.setString(69,cbachg);
              pstmt.setString(70,riskacc);
              pstmt.setString(71,marsitem);
              pstmt.setString(72,gccrfp);
              pstmt.setString(73,applcomp);
              pstmt.setString(74,capexpend);
              pstmt.executeUpdate();
    if anyone sees anything flawed here, please let me know!
    Thanks!
    Message was edited by:
    bpropes20
    Message was edited by:
    bpropes20
    Message was edited by:
    bpropes20

    What a mess. First off, the line pstmt.setInt(1,++lastRowNum); just needs to go away. You're already using a sequence to set the value for the primary keys, you don't need to add a mistake like this.
    I then count 73 question marks (you can verify, I'm not counting again.) That would mean that your indices are off by one, and the ArrayIndexOutOfBounds is probably coming from pstmt.setString(74,capexpend); Dump the ++lastRowNum line, change all of your indices (after verifying the bind count!) and try it again.
    You can see an inherent weakness in the PreparedStatement clauses - one change means manually rewriting all of the indices. A solution is dumping all of your bind values into a List, then loop through the list to do your setXXX statements. If all binds are not of the same type, you can bind the values to some object that identifies type and use those objects in the list instead of the values. A little more complex, but easier to maintain in my opinion.

Maybe you are looking for