Results 1 to 2 of 2
  1. #1
    hill0093 is offline Member
    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0

    Default String index doubled

    This subroutine (method):
    Java Code:
    protected void tryFixTemperature(int restBegin,StringBuffer lineBuf) { 
      int lgt=lineBuf.length(); 
      if((lineBuf.charAt(restBegin)==' '))lineBuf.insert(',',restBegin); else 
      if((lineBuf.charAt(restBegin)=='.')||(lineBuf.charAt(restBegin)=='1')) { 
        System.out.println("restBegin="+restBegin+":"+lineBuf); 
        lineBuf.deleteCharAt(restBegin); 
        System.out.println("restBegin="+restBegin+":"+lineBuf); 
        lineBuf.insert(',',restBegin); 
      } 
    ........
    gives this output:
    Java Code:
    restBegin=22:francineh,1963052608051 I 97.9,
    restBegin=22:francineh,196305260805 I 97.9,
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 44
            at java.lang.AbstractStringBuilder.insert(Unknown Source)
            at java.lang.StringBuffer.insert(Unknown Source)
            at java.lang.StringBuffer.insert(Unknown Source)
            at CkCalMn0.tryFixTemperature(CkCalMn0.java:93)
            at CkCalMn0.listAllTimeProblems(CkCalMn0.java:68)
            at CkCalMn0.main2(CkCalMn0.java:83)
            at CkCalMn0.main(CkCalMn0.java:28)
    There has to be something wrong with the java system.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,051
    Blog Entries
    7
    Rep Power
    23

    Default Re: String index doubled

    You do realize that the unicode value of the comma character happens to be 44?

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Finding Character at a Certain Index in a String?
    By Yaviel in forum New To Java
    Replies: 3
    Last Post: 02-09-2012, 12:59 AM
  2. String index out of range: -1 Error.
    By ashishb4 in forum New To Java
    Replies: 12
    Last Post: 09-28-2011, 07:32 PM
  3. Replies: 0
    Last Post: 12-03-2010, 07:07 AM
  4. String index out of range: -1 Please Help
    By davetheant in forum New To Java
    Replies: 22
    Last Post: 09-11-2010, 12:32 AM
  5. find index of string in another string
    By Sdannenberg3 in forum New To Java
    Replies: 4
    Last Post: 03-04-2010, 11:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •