3 Replies Latest reply: May 20, 2010 4:04 PM by 843810 RSS

    java.lang.StringIndexOutOfBoundsException

    843810
      Hello Everyone,

      I am getting same error as

      java.lang.StringIndexOutOfBoundsException: String index out of range: 0
      at java.lang.String.charAt(String.java:558)

      Here is the code:

      String resourceNo[] = p_request.getStringValues(RESOURCENO);
      int resLength = resourceNo.length ;
      String unitSerial[] = getReqStringValues(p_request,UNITSERIAL,resLength) ;
      String numOfUnit[] = getReqStringValues(p_request,UNITNO,resLength) ;
      String unitType[] = getReqStringValues(p_request,UNITTYPE,resLength) ;
      String allowsplit[] = getReqStringValues(p_request,ALLOWSPLIT,resLength) ;
      String moveunit[] = getReqStringValues(p_request,MOVEUNIT,resLength) ;
      String processallocation[] = getReqStringValues(p_request,PROCESSALLOCATION,resLength) ;
      String confirmallocation[] = getReqStringValues(p_request,CONFIRMALLOCATION,resLength);

      char uType ='E';
      double NoOfUnits = 0;
      double SConversion = 0;
      double LConversion = 0;
      double PConversion = 0;
      double DConversion = 0;
      AllocateProductStat allocPrd = null;
      for (int i = 0; i < resourceNo.length; i++) {
      if((resourceNo.trim()!= null) && !(resourceNo[i].equals(" "))&& (resourceNo[i].trim().length()>1)){
      allocPrd = new AllocateProductStat();
      allocPrd.setResourceNbr(Product.getProductCode(resourceNo[i]).trim());
      allocPrd.setAgainstInv(YES) ;
      uType = unitType[i].charAt(0); // this is the line where i am getting error
      ProductSingleton productRetriever = ProductSingleton.getInstance() ;
      Product prod = productRetriever.getProduct(resourceNo[i].trim());
      ProductPackage productPkg = null;
      try {
      productPkg = prod.getPackaging() ;
      SConversion = productPkg.getLamps(ProductUnit.CARTON,1) ;
      LConversion = productPkg.getLamps(ProductUnit.LAYER,1) ;
      PConversion = productPkg.getLamps(ProductUnit.PALLET,1) ;
      DConversion = productPkg.getLamps(ProductUnit.DOUBLE,1) ;
      } catch (LazyUpdateIncompleteException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }


      I am not sure why it is coming there need help ASAP
      Thanks for all your effort

      Edited by: Oak99 on Apr 28, 2010 6:02 AM
        • 1. Re: java.lang.StringIndexOutOfBoundsException
          800560
          Oak99 wrote:
          I am getting same error as

          java.lang.StringIndexOutOfBoundsException: String index out of range: 0
          at java.lang.String.charAt(String.java:558)
          I am guessing there is more to the error message. I would expect that someplace in the stacktrace, there is one or more lines that indicate lines of your code. That is important information in order to resolve the problem. I am guessing you have a String somewhere whose value is "" (empty String) and you are trying to do something that expects the String to contain at least 1 char.
          • 2. Re: java.lang.StringIndexOutOfBoundsException
            jschellSomeoneStoleMyAlias
            Use code tags when you post code
            if((resourceNo.trim()!= null)
            I am rather certain that either that will always be true or it will at some time throw a null pointer exception when it isn't true.
            • 3. Re: java.lang.StringIndexOutOfBoundsException
              843810
              Oak, you are not posting the whole stacktrace, nor the class.

              If you dont want to expose private or corporative information you should use a stacktrace analyzer to solve the problem.

              I would post a link to the one we use but usually gets powned by admins. :)

              Regards