Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

StringIndexOut OfBoundsException

 
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get this error "StringIndexOutOfBoundsException" when my input string is st= "Hold State,0,0,0,0,0,0,0,0"

The code below shows what I'm trying to do, create a StingBuffer os size 8 from the input



any ideas?
 
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use the constructor of StringBuffer that takes an int parameter, it does not create a StringBuffer with that many characters. It creates a StringBuffer with that capacity.

The StringBuffer will have no characters in it.
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nikos,

Are you trying to split obtained the contents of the comma-delimited String? Read the Java API and you'd notice that StringTokenizer is not recommended for usage anymore, except in supporting legacy codes.

As of JDK 1.4 and later, you could use the split method of String class.



This way, your codes is easier to maintain & understand. There's also performance gain involved, if I'm not mistaken.
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it was helpful

it now works


cheers
 
    Bookmark Topic Watch Topic
  • New Topic