String Index out of bound exception

I am trying to get substring from string. I have the following
String var = "20051221032435"
String var2 = var.substring(0,4)+"/"+var.substring(4,2)+"/"+var.substring(6,2)However, when i tried step by step run, it showed the first part (0,4) substring
correctly, but shows StringIndexOutofBoundException when moving to the second substring.
Why am i getting the above exception? how can it be solved?
basically, im just trying to convert the var to YYYY/MM/DD HH:MM:SS time format.

The first argument is the beginning index, and the second argument is the ending index. The second argument is not the length of the substring (which is IMO more conventional, but sadly not the way it works).
BTW, you do not need to do all of this. To parse dates use java.text.DateFormat. To extract parts of dates or manipulate them, use java.util.Calendar.
- Saish

Similar Messages

  • String index out of bounds?

    hi, i am writing a java program which reads in a file and then error checks it, once its done this it will output it to another file.
    It was working fine until i tried writing another method, now it keeps telling there is a string index out of bounds exception with the 'charAt' method. I have uploaded all the necessary files to compile and run the program.
    I am unsure of what the problem is so id be grateful of you would be able to check it out. If it helps i programmed and compiled this problem in netbeans 3.6.
    I uploaded it here: http://www.megaupload.com/?d=45QHZYN1
    you have to wait 45 seconds, the timer is in the right hand corner before you can begin download

    try
          {   System.out.println("2");
              Properties props   = new Properties();
              File file          = new File(System.getProperty("user.home") + File.separator + configFileName);
              BufferedInputStream bis = new BufferedInputStream(new FileInputStream (file));
              props.load(bis);
              if(bis != null)
                  bis.close();
              // Load the information from the properties file.
              String driver = (String)props.get("DB_DRIVER");
              String user    = (String)props.get("DB_USERNAME");
              String passwd  = (String)props.get("DB_PASSWORD");
              String url     = (String)props.get("DB_URL");
              conManager = ConnectionManager.getInstance(driver, user, passwd, url);
    logFilename = fileName.substring(0,fileName.lastIndexOf(".")) + ".log";
              System.out.println("log file name :: " + logFilename);
              fout = new FileOutputStream(new File(logFilename));
         catch (Exception e)
             e.printStackTrace();
      public static void main(String[] args)
        FormsRefresher formsRefresher = new FormsRefresher();
        String filename = "D:\\FCC\\FMB\\CLDUDCMT.fmb";   
        String username ="BPELDEMO";
        String pwd = "BPELDEMO";
        String url = "jdbc:oracle:thin:@PLUTO:1521:seriousim";
        String filename = args[8];
        formsRefresher.initialize(filename);
        formsRefresher.processForm(filename);
    }I am getting the error in the lines quoted bold
    This is the code and i am getting another error also along with that.
    That is Unsatisfiedlink error
    Message was edited by:
    Feroz_CG

  • String index out of bounds... issue regarding checking for non-integers

    okay. i have been racking my brain about this for the last couple of days. i looks like everything is alright, but i keep getting string index out of bounds exception: string index out of range 1.
    heres the code.
                   for(int x=0; x<size; ++x)
                        count=x+1;
                        System.out.println("Please enter value #"+count+(":"));
                        numnum=console.nextLine();
                        if(Character.isDigit(numnum.charAt(x)))
                             goodInput=true;
                        if(!goodInput)
                             System.out.print("Please Enter Only Integers!");
                        else
                             values[x]=Integer.parseInt(numnum);
    its probably something really stupid, but if someone can figure this out, id be most grateful.
    -thanks

    Be sure values contains data.
    Then make sure that size = values.length
    Either you don't have any data to iterate through, or the size variable is too big. So it's trying to search in parts of the array that don't exist.

  • Java Index Out Of Bounds Exception error

    In the Query Designer when I choose access type for Result value as Master data, and execute, I get the following java Index Out Of Bounds Exception error:
    com.sap.ip.bi.webapplications.runtime.controller.MessageException: Error while generating HTML
         at com.sap.ip.bi.webapplications.runtime.impl.Page.processRequest(Page.java:2371)
         at com.sap.ip.bi.webapplications.runtime.impl.Page.doServerRedirect(Page.java:2642)
         at com.sap.ip.bi.webapplications.runtime.impl.Page.doProcessRequest(Page.java:2818)
         at com.sap.ip.bi.webapplications.runtime.impl.Page.processRequest(Page.java:2293)
         at com.sap.ip.bi.webapplications.runtime.controller.impl.Controller.doProcessRequest(Controller.java:841)
         at com.sap.ip.bi.webapplications.runtime.controller.impl.Controller.processRequest(Controller.java:775)
         at com.sap.ip.bi.webapplications.runtime.jsp.portal.services.BIRuntimeService.handleRequest(BIRuntimeService.java:412)
         at com.sap.ip.bi.webapplications.runtime.jsp.portal.components.LauncherComponent.doContent(LauncherComponent.java:21)
         at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:209)
         at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114)
         at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
         at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
         at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
         at com.sapportals.portal.prt.component.PortalComponentResponse.include(PortalComponentResponse.java:215)
         at com.sapportals.portal.prt.pom.PortalNode.service(PortalNode.java:645)
         at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
         at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
         at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
         at com.sapportals.portal.prt.core.PortalRequestManager.runRequestCycle(PortalRequestManager.java:753)
         at com.sapportals.portal.prt.connection.ServletConnection.handleRequest(ServletConnection.java:240)
         at com.sapportals.portal.prt.dispatcher.Dispatcher$doService.run(Dispatcher.java:522)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sapportals.portal.prt.dispatcher.Dispatcher.service(Dispatcher.java:405)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.servlet.InvokerServlet.service(InvokerServlet.java:156)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:387)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:365)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:944)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:266)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:160)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    Caused by: com.sap.ip.bi.base.exception.BIBaseRuntimeException: Error while generating HTML
         at com.sap.ip.bi.webapplications.ui.items.UiItem.render(UiItem.java:380)
         at com.sap.ip.bi.webapplications.runtime.rendering.impl.ContainerNode.render(ContainerNode.java:62)
         at com.sap.ip.bi.webapplications.runtime.rendering.impl.PageAssemblerRenderingRoot.processRendering(PageAssemblerRenderingRoot.java:50)
         at com.sap.ip.bi.webapplications.runtime.impl.Page.processRenderingRootNode(Page.java:3188)
         at com.sap.ip.bi.webapplications.runtime.impl.Page.processRendering(Page.java:2923)
         at com.sap.ip.bi.webapplications.runtime.impl.Page.doProcessRequest(Page.java:2877)
         at com.sap.ip.bi.webapplications.runtime.impl.Page.processRequest(Page.java:2293)
         ... 39 more
    Caused by: java.lang.IndexOutOfBoundsException: fromIndex = -7
         at java.util.SubList.<init>(AbstractList.java:702)
         at java.util.RandomAccessSubList.<init>(AbstractList.java:860)
         at java.util.AbstractList.subList(AbstractList.java:569)
         at com.sap.ip.bi.bics.dataaccess.base.impl.ModifiableList.remove(ModifiableList.java:630)
         at com.sap.ip.bi.bics.dataaccess.consumer.impl.queryview.resultset.RsDataCells.removeRows(RsDataCells.java:480)
         at com.sap.ip.bi.bics.dataaccess.consumer.impl.queryview.resultset.RsAxis.removeTuples(RsAxis.java:550)
         at com.sap.ip.bi.bics.dataaccess.consumer.impl.queryview.resultset.RsAxis.applyResultVisibility(RsAxis.java:1312)
         at com.sap.ip.bi.bics.dataaccess.consumer.impl.queryview.resultset.RsAxis.applyResultVisibility(RsAxis.java:1326)
         at com.sap.ip.bi.bics.dataaccess.consumer.impl.queryview.resultset.RsAxis.applyResultVisibility(RsAxis.java:1326)
         at com.sap.ip.bi.bics.dataaccess.consumer.impl.queryview.resultset.RsAxis.applyResultVisibility(RsAxis.java:1326)
         at com.sap.ip.bi.bics.dataaccess.consumer.impl.queryview.resultset.RsAxis.applyResultVisibility(RsAxis.java:1272)
         at com.sap.ip.bi.bics.dataaccess.consumer.impl.queryview.resultset.RsAxis.applyResultVisibility(RsAxis.java:1170)
         at com.sap.ip.bi.bics.dataaccess.consumer.impl.queryview.resultset.ResultSet.applyPostProcessing(ResultSet.java:282)
         at com.sap.ip.bi.bics.dataaccess.consumer.impl.queryview.resultset.ResultSet.refreshData(ResultSet.java:262)
         at com.sap.ip.bi.bics.dataaccess.consumer.impl.queryview.QueryView.getResultSet(QueryView.java:267)
         at com.sap.ip.bi.webapplications.ui.items.analysis.control.AcPivotTableInteractive.checkResultSetState(AcPivotTableInteractive.java:368)
         at com.sap.ip.bi.webapplications.ui.items.analysis.control.AcPivotTableExport.validateDataset(AcPivotTableExport.java:249)
         at com.sap.ip.bi.webapplications.ui.items.analysis.control.AcPivotTableInteractive.buildUrTree(AcPivotTableInteractive.java:282)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:33)
         at com.sap.ip.bi.webapplications.ui.framework.base.composites.UiRootContainer.iterateOverChildren(UiRootContainer.java:40)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.advancedcontrols.bridge.AcItemBridge.iterateOverChildren(AcItemBridge.java:63)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.unifiedrendering.controls.FlowLayoutItem.iterateOverChildren(FlowLayoutItem.java:63)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.unifiedrendering.controls.FlowLayout.iterateOverChildren(FlowLayout.java:69)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.framework.base.composites.UiRootContainer.iterateOverChildren(UiRootContainer.java:40)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.advancedcontrols.bridge.AcItemBridge.iterateOverChildren(AcItemBridge.java:63)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.unifiedrendering.controls.MatrixLayoutCell.iterateOverChildren(MatrixLayoutCell.java:63)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.unifiedrendering.controls.MatrixLayoutRow.iterateOverChildren(MatrixLayoutRow.java:56)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.unifiedrendering.controls.MatrixLayout.iterateOverChildren(MatrixLayout.java:69)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.container.matrixlayout.control.AcMatrixControlGrid.iterateOverChildren(AcMatrixControlGrid.java:40)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.framework.base.composites.UiRootContainer.iterateOverChildren(UiRootContainer.java:40)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.advancedcontrols.bridge.AcItemBridge.iterateOverChildren(AcItemBridge.java:63)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.unifiedrendering.controls.Group.iterateOverChildren(Group.java:63)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.container.group.control.AcGroupControl.iterateOverChildren(AcGroupControl.java:259)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.framework.base.composites.UiRootContainer.iterateOverChildren(UiRootContainer.java:40)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.advancedcontrols.bridge.AcItemBridge.iterateOverChildren(AcItemBridge.java:63)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.unifiedrendering.controls.FlowLayoutItem.iterateOverChildren(FlowLayoutItem.java:63)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.unifiedrendering.controls.FlowLayout.iterateOverChildren(FlowLayout.java:69)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.framework.base.composites.UiRootContainer.iterateOverChildren(UiRootContainer.java:40)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.advancedcontrols.bridge.AcItemBridge.iterateOverChildren(AcItemBridge.java:63)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.unifiedrendering.controls.Group.iterateOverChildren(Group.java:63)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.container.group.control.AcGroupControl.iterateOverChildren(AcGroupControl.java:259)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.framework.base.composites.UiRootContainer.iterateOverChildren(UiRootContainer.java:40)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.process(CompositeBuildUrTreeTrigger.java:36)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.CompositeBuildUrTreeTrigger.start(CompositeBuildUrTreeTrigger.java:59)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.ExtendedRenderManager.triggerComposites(ExtendedRenderManager.java:69)
         at com.sap.ip.bi.webapplications.ui.framework.base.impl.BICompositeManager.renderRoot(BICompositeManager.java:79)
         at com.sap.ip.bi.webapplications.ui.items.UiItem.render(UiItem.java:376)
    Any help in solving this error is highly appreciated. Points will be given
    Best Regards,
    Vidyut K Samanta

    Hi.
    Go to line 9 of your code.
    You are trying to use an array there.
    Suppose you have an array x[4] - this array has 4 elements indexed 0..3.
    you are trying to access an element with an index higher than 3.
    Nimo.

  • Please iam getting index out of bound exception can any body solve my probl

    Dear all
    iam doing aproject in swing in that one class iam using the below method. Iam getting index out of bound exception. Actually iam trying to access the more that 50mb file at that time its giving out of memory exception after that iam using this method now its giving index out of bound exception, when it is going second time in the while loop. can any body solve my problem. Please give me the solution . Ill be very thankful to you.
    public Vector getFileContent(File fileObj){
    FileInputStream fis = null;
    DataInputStream dis = null;
    Vector v = new Vector();
    byte[] data = null;
    int pos = 0;
    int chunk = 10000;
    int sizePos = 0;
    try{
    fis = new FileInputStream(fileObj);
    int size = (int)fileObj.length();
    dis = new DataInputStream(fis);
    int k = 1;
    if(size <10000){
    data = new byte[size];
    //v.addElement(dis.readFully(data));
    dis.readFully(data);
    v.addElement(data);
    else {
    while(pos < size){
    sizePos = size - chunk*k;
    if(sizePos > 10000){
    chunk = 10000;
    else{
    chunk = sizePos;
    data = new byte[chunk];
    dis.read(data, pos, chunk);
    v.addElement(data);
    System.gc();
    pos = pos + chunk + 1;
    regards,
    surya

    pos = pos + chunk + 1;Why the +1??

  • String Index out of Bounds Error in 8i

    Hi!
    My requirement is to load a java file in to oracle 8i database. My program makes use of XSL to format a XML and insert the re-done XML into 8i but the problem i am facing is, i not able to resolve the dependency between XSL file and Java class ie., during run time the Java class is not able find the XSL file which is in the same path so i am getting "File Not Found Exception".
    i tried the following statements
    "//MyXsl.xsl" and
    "MyXsl.xsl" and "MyXsl.xsl"
    within the Java file but neither of these statements worked out. I checked the JAR which i loaded into 8i it contained both the XSL file and Java file in the same path.
    So, i hard coded the XSL logic into the Java file itself as a String but i am getting the following error.
    org.apache.xalan.xslt.XSLProcessorException: String index out of range: 0
    and this is how i defined the string
    String xslDefinition = "<?xml version=\"1.0\"?>\n"+
    "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"+
    "<xsl:param name=\"pid\"></xsl:param>\n"+
    "<xsl:output method=\"xml\" omit-xml-declaration=\"yes\"/>\n"+
    " <xsl:template match=\"root\">\n"+
    " <xsl:element name=\"item\">\n"+
    "<xsl:attribute name=\"id\">\n"+
    " <xsl:value-of select=\"$pid\"/>\n"+
    "</xsl:attribute>\n"+
    "<xsl:copy-of select=\"product_name\"/>\n"+
    "<xsl:copy-of select=\"product_merchant\"/>\n"+
    "<xsl:copy-of select=\"product_price\"/>\n"+
    "<xsl:copy-of select=\"product_URL\"/>\n"+
    "<xsl:copy-of select=\"product_url\"/>\n"+
    "</xsl:element>\n"+
    "</xsl:template>\n"+
    "</xsl:stylesheet>\n";
    can anyone help me?
    thanks in advance.

    Hi.
    The Xalan processor is an Apache technology. Please ask Xalan-specific questions on the Apache mailing lists.
    Thanks.

  • Array Index out of bound exception

    public Name[] getName() {
              Name[] retVal = new Name[0];
              retVal[0] = this.getNameInstance();
              return retVal;
         public void setName(Name[] theName) {
              theName[0]=this.getNameInstance();
         private Name myNameInstance = new Name();
         public void setNameInstance(Name theNameInstance) {
              if(isValidName(theNameInstance)){
              myNameInstance = theNameInstance;
         public Name getNameInstance() {
              return myNameInstance;
         }I am getting an array Index out of bound eception in the method setName, Can any one tell me where I am doing wrong?

    The array passed in must be empty. I suggest using the debugger for problems like these. If you don't know how to use the debugger, here's a start:
    (Assuming you have a debugger, any IDE you'd be using will)
    1. Set a breakpoint on or before your line of question. In this case, place it on the line of code in your setName() method. Set a breakpoint by either right clicking on that line and selecting "Add breakpoint," or simply click on the far left side of the editor window, right next to the line number. Either way, a little dot will appear to mark the breakpoint.
    2. Execute your code in Debug mode rather than release mode. This might mean clicking on the little bug-looking icon "Debug" rather than "Run."
    3. Your code will execute and you'll enter the debug perspective when that breakpoint is reached. There, in the variables window, you'll see your array and any information about it, particularly its size and contents.

  • String index out of bound

    Hi,
    I am getting the following error-->
    "java.lang.StringIndexOutOfBoundsException: String index out of range: 58
    at java.lang.String.charAt(String.java:444) "can anyone tell me what is the root cause of such errors and how to avoid them?
    regards,
    Anshuman

    HI All yet the problem is solved for
    java.lang.StringIndexOutOfBoundsException: String index out of range: 1
    if(response.substring(0,1).equals("1")==false)
                                       //     if (!response.startsWith("1"))
                                                 writeLogs("Error: For "+ e4p_ConfigurationLoader.getPartnerIdName(partner_ids.get(p).toString())+" Partner id  "+partner_ids.get(p).toString()+": "+response.substring(3,response.length()));
                                                 continue;//take next file
                                                 //collect the response in file
                                            }since this code of line is aasociated witth this lines
    //check the response and get the public key
                   if(response.charAt(0)!='1')
                        String colectRes=response.substring(2,response.length());
                        unableToAdduserid=1;
                        pgpMessaging(colectRes);
                   else
                        response=response.substring(1,response.length());
                        int indexval=response.indexOf("$"); // read the user id pass from pgp import
                        if(indexval==-1)
                        else
                             String extractid=response.substring(indexval+2,response.length()-1);
                             userid=extractid;
                             updateUserid();
                        setFlagValues();
                        if(filePath.endsWith("/")==true)
                             filePath=filePath.substring(0,filePath.length()-1);
                        if(filePath.startsWith("/")==false)
                             filePath=e4p_ConfigurationLoader.relative_path+filePath;                    
                        else
                             filePath=e4p_ConfigurationLoader.relative_path+filePath.substring(1,filePath.length());
                        checkFileExist(); // check the file exist for encryption
                        if(directoryErr==0)
                             setNamePath();//no error reporting
                        //     doEncryption();
                        //     makeSuccessString();//no error reporting
                             makePublicErrorString();
                             if(userid.equals("") || userid==null)
                                  if(userIdNotmention==1)
                                  pgpMessaging("");                         
                             else
                                  doEncryption();                              
                        else
                             pgpMessaging("");
                        if(fileNotFoundErr==1)
                             pgpMessaging("");
                        if(ioExceptionErr==1)
                             pgpMessaging("");
                        if(keyErrFlag==1)
                             pgpMessaging("");
                        if(keyNotSigned==1)
                             pgpMessaging("");
                        if(fileEncrytionFlag==1)
                             pgpMessaging("");
                             updateDataBase();//update file name from txt to .asc file
                                                              //error reporting updation error
                             if(databaseUpdationErr==1)
                                  pgpMessaging("");
              }          

  • New InitialContext() gets String index out of bounds

    Context ctx = null;
    ctx = new InitialContext();
    DataSource dataSource = (DataSource) ctx.lookup("jdbc/datasource");
    connection = dataSource.getConnection();
    I get:
    String index out of range: -1
    weblogic.jndi.Environment.getContext(Environment.java:308)
    weblogic.jndi.Environment.getContext(Environment.java:285)
    weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117)
    javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
    javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    javax.naming.InitialContext.init(InitialContext.java:223)
    javax.naming.InitialContext.<init>(InitialContext.java:175)
    Earlier when I had provider_url specified I didn't get this problem, but it should be working without specifing provider_url...
    And well now it doesn't work with provider_url localhost since they set -Djava.net.preferIPv4Stack=true
    Which made so it stopped listening to localhost:port...
    Does someone know a possible solution for:
    1. String index of range
    2. the preferIPv4Stack thingy, which makes the listeners to stop listening to localhost:port

    Be sure values contains data.
    Then make sure that size = values.length
    Either you don't have any data to iterate through, or the size variable is too big. So it's trying to search in parts of the array that don't exist.

  • Index out of Bounds Exception in for loop.

    Occasionaly with the code below, i get an index out of bounds error, index 1, size 1, however the for loop should ensure that it never calls the getActorLocation method if the index is the same size as the arrayList size.
    Im having one of those days, and i just cant see what error i have made.
    Perhaps i need coffee? lol
    Cheers
    James
    private void checkMemoryIntegrity(){
            Actor actor = actorList.get(actorIndex);
            ArrayList<Integer> inRangeList = getActorsInMemoryRange(actor, actor.getRange());
            inRangeList.trimToSize();
            for (int i = 0; i < inRangeList.size();i++){
                if (inRangeList.size() != 0){
                    actor = brainState.getActorLocation(i); //<<<<<<<<< problem line
                    if (!actorList.contains(actor)){
                        brainState.actorLocations.remove(i);
    public ArrayList <Integer> getActorsInMemoryRange(Actor actor, int range){
            int i = 0;
            int x = actor.getX();
            int y = actor.getY();
            ArrayList <Integer> inRangeList = new ArrayList <Integer> ();
            Actor compActor;
            while (i< brainState.actorLocations.size())
                compActor = brainState.getActorLocation(i);
                int xDist = x - compActor.getX();
                if ( (xDist >= (-1) * range) && (xDist <= range) ){
                    int yDist = y - compActor.getY();
                    if ( (yDist >= (-1) * range) && (yDist <= range) ){
                        inRangeList.add(i);
                i++;
            return inRangeList;
        }

    I was thinking it might be easier to do it this way:
    Iterator<Actor> i = actorLocations.iterator();
    while(i.hasNext())
        if (!actorList.contains(i.next())) {
            i.remove();
    }It sounds like you have an equals() method which compares the x and y locations of the actor. If not then you will have to enclose the remove in an if block which compares the actor location. Does that make sense?
    Edit: contains uses the equals method.
    Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that
    (o==null ? e==null : o.equals(e)).Edited by: Edward_Kimber on May 23, 2008 11:43 AM

  • Why am i getting an index out of bounds exception

    I just want to read some bytes at the end of an mp3 file.
    File file = new File(fd.getDirectory() + File.separator + fd.getFile());
                try {
                     FileInputStream fileInputStream = new FileInputStream(file);
                     byte[] fileSnippet = new byte[100];
                     int startPosition = (int)file.length() - 500;
                     fileInputStream.read(fileSnippet, startPosition, 100);

    fileInputStream.read(fileSnippet, startPosition, 100);This does not tell it to seek (hint, hint) to startPosition and read 100 bytes. It is telling it to read from the current position into the buffer starting at index "startPosition" in that buffer. If startPosition is >= 100, then that's clearly out of bounds.

  • Expected index out of bound exception

    my teacher give me this code:
    @Test(expected = IndexOutOfBoundsException.class)
      public void testShouldThrow() {
        OurList<String> list = new OurArrayList<String>();
        list.insertElementAt(1, "A");
      }I don't understand what he means by the expected = IndexOutOfBoundException.class
    I mean what he is trying to say here is that I can't insert an element at index 1 if index 0 is not yet filled. But I tried this code on j unit and it compiles?? Can somebody explain this to me

    I see..so the test passed because the indexOutOfBound
    worked. Can you tell me what does the syntax means?
    expected IndexOutOfBoundException.classWell I'm not so familiar with the annotation syntax and wasn't aware of JUnit having @Test(...) annotations, but I'd suggest reading up on JUnit at their website http://junit.org/index.htm
    But intuitively speaking, it means when the method terminates, the JUnit framework sees the return value or exception, and compares its class with the above. Basically they have a catch block behind the scenes something like this:
    catch (Throwable t)
      if (t.getClass() == expectedClass)
        testPassed();
      else
        testFailed();
    }where expectedClass in this case equals IndexOutOfBoundsException.class

  • Throwing index out of bound exception- please explain to fix the error

    import java.util.StringTokenizer;
    import java.lang.String;
    public class tokenize
              String s="I have learned that people will forget what you said, people will forget what you did, but people will never forget how you made them feel. ";
              String s1="Nature always wears the colors of the spirit.";
                        public void noofwords()
                             StringTokenizer str= new StringTokenizer(s," ");
    StringTokenizer str1= new StringTokenizer(s1," ");
                             System.out.println("the no of words in the string s is: "+str.countTokens()+" and the number of words in s1 is: "+str1.countTokens);
                        public void nooflines()
                             StringTokenizer str2= new StringTokenizer(s1,".,?");
                             StringTokenizer str3 = new StringTokenizer(s,".,?");
                             System.out.println("the number of lines in string s is: "+str3.countTokens()+" "+"and number of lines in the string s1 is: "+str2.countTokens());
                        public void noofchars()
                             System.out.println("no of characters in string s is: "+s.length()+ " " +"and the number of lines in the string s1 is : "+s1.length());
                        public void noofvowels()
                             StringTokenizer str4 = new StringTokenizer(s," ");
                             String strpackets;
                             int count =0;
                             if(str4.hasMoreElements())
                                  strpackets= str4.nextToken();
                                  for( int a=0;a<=strpackets.length();a++)
                                       char c= strpackets.charAt(a);
                                            if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
                                                 count++;
                             System.out.println("the number of vowels in the sring s is: "+count);
         public static void main(String[] args)throws StringIndexOutOfBoundsException
              tokenize tze = new tokenize();
              tze.noofwords();
              tze.noofchars();
              tze.nooflines();
              tze.noofvowels();
    Edited by: 881507 on Sep 10, 2012 9:46 PM

    Provide the exception stacktrace.
    Post your code inside the code tag.
    881507 wrote:
    public class tokenize Follow the convention to writing a class.
    public class Tokenize 881507 wrote:System.out.println("the no of words in the string s is: "str.countTokens()" and the number of words in s1 is: "+str1.countTokens);is this compiled?
    881507 wrote:
    char c= strpackets.charAt(a);this is the point which throw the exception.
    It should be
    for( int a=0;a<strpackets.length();a++)

  • Index out of bound exception

    Hi All,
    I am using ESS/MSS. One of my user when try to open an item in the UWL, he gets the following error
    Critical error
    Index: 0, Size: 0
    Java.lang.Indexoutofboundexception:Index: 0, Size: 0
    Can anyone advise me in this?
    Thanks!
    Swarnaprakash

    For a given UWL/Workflow item, there should be an associated leave request item waiting for the manager to approve or reject.
    However, in some cases, the leave request item would not exist at the time of clicking on the UWL item. This is probably because the leave request was approved/completed from some where else (by a time administrator) and the workflow item is not aware of this change.
    If the workflow is not updated when the leave request was completed, then this could lead to the inconsistency.
    I would suggest you to check the status of the leave request that is creating the issue from transaction PTARQ. If the leave request is already completed, then you can just delete the work item from the backend system.
    There is no clear cut solution for this problem as it is more of a data inconsistency issue.
    Hope that helps !!
    - Shanti

  • Problem while connecting to mysql(Array Index Out Of Bound Exception)

    hi...
    java.sql.SQLException: Unable to connect to any hosts due to exception: java.lang.ArrayIndexOutOfBoundsException: 40
    this is the exception which i got.. when iam connecting to mysql...
    i alredy done googling...but....i didn't find any solution...
    pls suggest me...
    waiting 4r u r reply....

    I got a similar error, but its different scenario.
    vo=getVO;
    vo.setApplyViewCreteria("ViewC");
    vo.setQueryMode(Database_Rows | Entity_Rows );
    vo.exceuteQuery();
    for my case executequery() throws the same stacjk trace
    after removing Entity_Rows i mean vo.setQueryMode(Database_Rows | Entity_Rows ); ---> vo.setQueryMode(Database_Rows );
    I didn't get this error.
    Some problem with adding entity rows.

Maybe you are looking for

  • What's the deal with bluetooth mice ?

    What's the deal with bluetooth mice ? I've never heard of any model yet that didn't come with loads of complain... (I've done my research) ... isn't there one that just works fine and that will for a few years like a standard mouse ? I would really l

  • How to recover iphoto library from recovery mode

    My macbook pro suddenly went on Utility Disk Mode and can only be accessed through recovery mode. I cannot even view the files. I'm willing to let everything go except for the photos and videos in the iphoto library. I don't know how to access my pho

  • Difference betwen loading a repository and connecting to a repository

    Hi, In the MDM console i see 2 options. 1) Load Reposiotry 2) Connect repository. I mount the mdm server. then i mount the mdm reposiotry and connect to it. After connecting i am able to log into the data import manager and data manager and choose th

  • Regading LSMW for VD01 transaction

    HI, This is KSR Saireddy. i am getting the problem in LSMW at the the STEP Create Batch Input Session.i am executing this step,now i am getting the file name as ZIMS_91_ZIMS_91_MIGRT_CUSTOMER.lsmw.conv after excuting it is giving the message that Tra

  • ASA VPN SSL 8.4.x : Using differents certificates by connection profile

    I want to use a different certificate by connection profile. Is-it possible on ASA 8.4 ? My first certificate is for vpn.itcom.fr associated to one connection profile and my second is for vpn.newitcom.fr associated to a second connection profile. Tha